Skip to content
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

Not able to make namespaces work #59

Closed
sanketsaurav opened this issue Jan 16, 2015 · 10 comments
Closed

Not able to make namespaces work #59

sanketsaurav opened this issue Jan 16, 2015 · 10 comments

Comments

@sanketsaurav
Copy link

I'm trying to create a namespace, but I'm not able to connect to the namespace from the client side.

Server:

func registerHandlers(server *socketio.Server) {
    server.Of("room1").On("connect", connectionHandler)
}

func connectionHandler(so socketio.Socket) {
    log.Println("on connection")
    so.Join("chat")
    so.On("chat message", func(msg string) {
        so.BroadcastTo("chat", "chat message", msg)
    })
}

Client:

var socket = io.connect("http://localhost:3000/room1");
socket.on('chat message', function(msg){
        $('#messages').append($('<li>').text(msg));
      });

Am I missing something?

@Dal-Papa
Copy link

Dal-Papa commented Feb 7, 2015

Hi Sanket,

Did you have any update on that ? I run into the same problem here.

Cheers.

@rykov
Copy link
Contributor

rykov commented Feb 8, 2015

+1

@navneetk
Copy link

I am also facing the same issue.
The socket.io client socket with a namespace does not get connected. It has socket.id property as undefined and connected as false.
Whereas on the server side any message sent to it from a client socket without namespace get echoed with namespace attached.

Frame sent => 42["message","hello"]
Frame received => 42/myspace,["message","hello from server /myspace"]

for the server code:

server.On("connection", func(so sio.Socket) {
    fmt.Printf("connected: %s of nsp: %s - %s -\n", so.Id(), so.Namespace(), server.Name())
    so.On("message", func(msg string) {
        fmt.Println("got message: ", msg)
        so.Emit("message", msg+" from server "+so.Namespace())
    })
...
})

server output:

connected: gdbWCxmHhk6VwHHh3Trv of nsp:  -  -
got message:  hello
sending message: message via socket gdbWCxmHhk6VwHHh3Trv having nsp:/myspace
[message hello from server /myspace]

the last two lines in server output comes from modified handler.go

func (h *socketHandler) Emit(message string, args ...interface{}) error {....}

@googollee
Copy link
Owner

I will try to figure out this issue.

@Nickstr
Copy link

Nickstr commented Mar 27, 2015

Having the same issue here, any updates on this?

fuel-shea added a commit to fuel-shea/go-socket.io that referenced this issue May 29, 2015
See: googollee#59

The socket.io client requires an echoed connect packet,
which is mising from the current code.

NOTE: I believe navneetk's example from Mar 18 2015 shows
a different issue.
@fuel-shea
Copy link
Contributor

@navneetk my fix may not solve your problem. It seems unrelated to the code I changed. I'm only able to confirm that without my fix, clients can't connect fully and with it, they are connected.

EDIT: This fix is needed, but not enough. I'm running into the same problem described above, even with my fix.

@collinglass
Copy link

Would really like to use this in production! Namespaces is a must. I made this little test app to compare node socket.io and go socket.io with namespaces. https://github.com/collinglass/socketio

@eliezedeck
Copy link

Is there any update on this? It's really not viable to build big applications with this library without namespace support.

@goodwong
Copy link

Hi Sanket,

Did you have any update on that ? I run into the same problem here.

Cheers.

@erkie
Copy link
Collaborator

erkie commented Feb 8, 2019

Closing this issue because it is old. There are a couple of newer issues with the same problem so please refer to those. Thanks!

@erkie erkie closed this as completed Feb 8, 2019
adrianmxb pushed a commit to adrianmxb/go-socket.io that referenced this issue Feb 6, 2020
Set state of closing before closing the socket
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests