diff --git a/README.md b/README.md index dde3d87..cd2123f 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Examples directory contains simple client and server. ### Installation - go get github.com/graarh/golang-socketio + go get github.com/gsocket-io/golang-socketio ### Simple server usage diff --git a/client.go b/client.go index deded6c..5aeba06 100644 --- a/client.go +++ b/client.go @@ -1,14 +1,15 @@ package gosocketio import ( - "github.com/graarh/golang-socketio/transport" + "github.com/gsocket-io/golang-socketio/transport" + "net" "strconv" ) const ( - webSocketProtocol = "ws://" + webSocketProtocol = "ws://" webSocketSecureProtocol = "wss://" - socketioUrl = "/socket.io/?EIO=3&transport=websocket" + socketioUrl = "/socket.io/?EIO=3&transport=websocket" ) /** @@ -21,7 +22,7 @@ type Client struct { /** Get ws/wss url by host and port - */ +*/ func GetUrl(host string, port int, secure bool) string { var prefix string if secure { @@ -29,7 +30,7 @@ func GetUrl(host string, port int, secure bool) string { } else { prefix = webSocketProtocol } - return prefix + host + ":" + strconv.Itoa(port) + socketioUrl + return prefix + net.JoinHostPort(host, strconv.Itoa(port)) + socketioUrl } /** diff --git a/examples/client.go b/examples/client.go index 6d1063d..9cbed61 100644 --- a/examples/client.go +++ b/examples/client.go @@ -1,8 +1,8 @@ package main import ( - "github.com/graarh/golang-socketio" - "github.com/graarh/golang-socketio/transport" + "github.com/gsocket-io/golang-socketio" + "github.com/gsocket-io/golang-socketio/transport" "log" "runtime" "time" diff --git a/examples/server.go b/examples/server.go index 340949e..b0d0e88 100644 --- a/examples/server.go +++ b/examples/server.go @@ -1,8 +1,8 @@ package main import ( - "github.com/graarh/golang-socketio" - "github.com/graarh/golang-socketio/transport" + "github.com/gsocket-io/golang-socketio" + "github.com/gsocket-io/golang-socketio/transport" "log" "net/http" "time" diff --git a/handler.go b/handler.go index 78c3636..6b7f6f2 100644 --- a/handler.go +++ b/handler.go @@ -2,9 +2,9 @@ package gosocketio import ( "encoding/json" - "github.com/graarh/golang-socketio/protocol" - "sync" + "github.com/gsocket-io/golang-socketio/protocol" "reflect" + "sync" ) const ( diff --git a/loop.go b/loop.go index 5e73c5b..ebca563 100644 --- a/loop.go +++ b/loop.go @@ -3,8 +3,8 @@ package gosocketio import ( "encoding/json" "errors" - "github.com/graarh/golang-socketio/protocol" - "github.com/graarh/golang-socketio/transport" + "github.com/gsocket-io/golang-socketio/protocol" + "github.com/gsocket-io/golang-socketio/transport" "net/http" "sync" "time" @@ -48,9 +48,9 @@ type Channel struct { ack ackProcessor - server *Server - ip string - requestHeader http.Header + server *Server + ip string + request *http.Request } /** diff --git a/send.go b/send.go index 07e8130..6bbb1d7 100644 --- a/send.go +++ b/send.go @@ -3,7 +3,7 @@ package gosocketio import ( "encoding/json" "errors" - "github.com/graarh/golang-socketio/protocol" + "github.com/gsocket-io/golang-socketio/protocol" "log" "time" ) diff --git a/server.go b/server.go index 7583633..376bc51 100644 --- a/server.go +++ b/server.go @@ -7,8 +7,8 @@ import ( "encoding/json" "errors" "fmt" - "github.com/graarh/golang-socketio/protocol" - "github.com/graarh/golang-socketio/transport" + "github.com/gsocket-io/golang-socketio/protocol" + "github.com/gsocket-io/golang-socketio/transport" "math/rand" "net/http" "sync" @@ -43,7 +43,7 @@ type Server struct { /** Close current channel - */ +*/ func (c *Channel) Close() { if c.server != nil { closeChannel(c, &c.server.methods) @@ -65,7 +65,14 @@ func (c *Channel) Ip() string { Get request header of this connection */ func (c *Channel) RequestHeader() http.Header { - return c.requestHeader + return c.request.Header +} + +/** +Get request +*/ +func (c *Channel) Request() *http.Request { + return c.request } /** @@ -278,6 +285,10 @@ func onDisconnectCleanup(c *Channel) { delete(c.server.rooms, c) } + go deleteSid(c) +} + +func deleteSid(c *Channel) { c.server.sidsLock.Lock() defer c.server.sidsLock.Unlock() @@ -304,7 +315,7 @@ func (s *Server) SendOpenSequence(c *Channel) { Setup event loop for given connection */ func (s *Server) SetupEventLoop(conn transport.Connection, remoteAddr string, - requestHeader http.Header) { + r *http.Request) { interval, timeout := conn.PingParams() hdr := Header{ @@ -317,7 +328,7 @@ func (s *Server) SetupEventLoop(conn transport.Connection, remoteAddr string, c := &Channel{} c.conn = conn c.ip = remoteAddr - c.requestHeader = requestHeader + c.request = r c.initChannel() c.server = s @@ -340,7 +351,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - s.SetupEventLoop(conn, r.RemoteAddr, r.Header) + s.SetupEventLoop(conn, r.RemoteAddr, r) s.tr.Serve(w, r) }