Exemple #1
0
func connectToServer() (connection.Connection, error) {
	// weeeee, global variables
	conn, err := net.Dial("tcp", string(porterIP)+porterPort.Port)
	if err != nil {
		return nil, err
	}
	return connection.NewSocketConn(conn), nil
}
Exemple #2
0
func socketListen(port string) {
	ln, err := net.Listen("tcp", port)
	if err != nil {
		logger.Errorf("Could not open socket for listening")
	}
	for {
		conn, err := ln.Accept()
		if err != nil {
			logger.Errorf("Could not accept connection from client")
			continue
		}
		sconn := connection.NewSocketConn(conn)
		gamehub.connRegister <- sconn
	}
}
Exemple #3
0
func handleConnection(netConn net.Conn) error {
	conn := connection.NewSocketConn(netConn)
	handler := request_handler.NewRequestHandler()
	for {
		logger.Infof("Handling a connection")
		request, err := conn.Read()
		if err != nil {
			logger.Warnf("Error reading request (%s)", err.Error())
			conn.Close()
			return err
		}
		logger.Debugf("Got request %s", string(request))
		response := handler.HandleRequest(request)
		logger.Debugf("Sent response %s", string(response))
		err = conn.Write(response)
		if err != nil {
			logger.Warnf("Error writing response (%s)", err.Error())
			conn.Close()
			return err
		}
	}
}
Exemple #4
0
func NewClient(conn net.Conn) *Client {
	return &Client{conn: connection.NewSocketConn(conn)}
}