Skip to content

Oh sorry, wrong place to put a issue! #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 6 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
@@ -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"
)

/**
Expand All @@ -21,15 +22,15 @@ 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 {
prefix = webSocketSecureProtocol
} else {
prefix = webSocketProtocol
}
return prefix + host + ":" + strconv.Itoa(port) + socketioUrl
return prefix + net.JoinHostPort(host, strconv.Itoa(port)) + socketioUrl
}

/**
Expand Down
4 changes: 2 additions & 2 deletions examples/client.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 2 additions & 2 deletions examples/server.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 2 additions & 2 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
10 changes: 5 additions & 5 deletions loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -48,9 +48,9 @@ type Channel struct {

ack ackProcessor

server *Server
ip string
requestHeader http.Header
server *Server
ip string
request *http.Request
}

/**
Expand Down
2 changes: 1 addition & 1 deletion send.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
25 changes: 18 additions & 7 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -43,7 +43,7 @@ type Server struct {

/**
Close current channel
*/
*/
func (c *Channel) Close() {
if c.server != nil {
closeChannel(c, &c.server.methods)
Expand All @@ -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
}

/**
Expand Down Expand Up @@ -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()

Expand All @@ -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{
Expand All @@ -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
Expand All @@ -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)
}

Expand Down