code: func newSocket(server *Server, bs backend.BackendSocket) *Socket {
  	// Create a new socket value.
  	s := &Socket{
  		server: server,
  		bs:     bs,
  
  		id:       utils.RandomString(socketIDLength),
  		channels: newChannels(),
  
  		writeChan:    bs.WriteChan(),
  		readChan:     bs.ReadChan(),
  		isClosedChan: bs.ClosedChan(),
  
  		pingTimer:   time.NewTimer(pingPeriod),
  		pingTimeout: time.NewTimer(pingResponseTimeout),
  	}
  
  	// Create the main channel.
  	s.mainChannel = s.Channel(mainChannelName)
  
  	// Call the on close method as soon as the socket closes.
  	go func() {
  		<-s.isClosedChan
  		s.onClose()
  	}()
  
  	// Stop the timeout again. It will be started by the ping timer.
  	s.pingTimeout.Stop()
  
  	// Add the new socket to the active sockets map.
  	// If the ID is already present, then generate a new one.
  	func() {
  		// Lock the mutex.
  		s.server.socketsMutex.Lock()
  		defer s.server.socketsMutex.Unlock()
  
  		// Be sure that the ID is unique.
  		for {
  			if _, ok := s.server.sockets[s.id]; !ok {
  				break
  			}
  
  			s.id = utils.RandomString(socketIDLength)
  		}
  
  		// Add the socket to the map.
  		s.server.sockets[s.id] = s
  	}()
  
  	// Start the loops and handlers in new goroutines.
  	go s.pingTimeoutHandler()
  	go s.readLoop()
  	go s.pingLoop()
  
  	return s
  }
docs: // newSocket creates a new socket and initializes it.