go-socket.io icon indicating copy to clipboard operation
go-socket.io copied to clipboard

socket close does not work on disconnect ?

Open AhmedX6 opened this issue 6 years ago • 3 comments

Hello,

In example I see that s.Close() is used on "bye" event. Is it possible to do it onDisconnect event after doing some operations?

When I do s.Close() on disconnect, I have "Did you forget to Close() the ReadCloser from NextReader?" after some time. But I closed it.

SocketIO in golang is a great work but I find it more complicated than before...

Regards

AhmedX6 avatar Nov 26 '19 23:11 AhmedX6

This issue duplicates to old issue #279

In example I see that s.Close() is used on "bye" event.

This message changed by "client namespace disconnect"

Is it possible to do it onDisconnect event after doing some operations?

What do you wanna print?

When I do s.Close() on disconnect, I have "Did you forget to Close() the ReadCloser from NextReader?" after some time. But I closed it.

It is so interesting. Please, Tell me about your socket.io-client version and golang version.

SocketIO in golang is a great work but I find it more complicated than before...

Thanks, but it is work by @googollee

sshaplygin avatar Nov 27 '19 20:11 sshaplygin

Hello,

I'm with go v1.12.

I don't want to print anything but for example, here is my code :

server.OnDisconnect("/", func(s socketio.Conn, msg string) {
		lenRoom := len(s.Rooms())
		if lenRoom > 0 {
			for i := 0; i < lenRoom; i++ {
				log.Println("Socket id:", s.ID(), "left:", s.Rooms()[i])
				server.LeaveRoom(s.Rooms()[i], s)
				server.BroadcastToRoom(s.Rooms()[i], "nbr_connected", server.RoomLen(s.Rooms()[i])-1)
			}
		}
		s.Close()
})

It's simple. But have this message when I use s.Close() here "Did you forget to Close() the ReadCloser from NextReader?"

AhmedX6 avatar Nov 29 '19 23:11 AhmedX6

@AhmedX6 At first, Why are you call Close function at the socket after disconnect them.

If you want leave from all rooms use - LeaveAll method and send for all what client disconnected from server please use SendAll method

sshaplygin avatar Dec 09 '19 18:12 sshaplygin