示例#1
0
文件: proxy.go 项目: Tactique/proxy
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
}
示例#2
0
文件: proxy.go 项目: Tactique/proxy
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
	}
}
示例#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
		}
	}
}
示例#4
0
func NewClient(conn net.Conn) *Client {
	return &Client{conn: connection.NewSocketConn(conn)}
}