kataras / neffos

A modern, fast and scalable websocket framework with elegant API written in Go
http://bit.ly/neffos-wiki
MIT License
574 stars 49 forks source link

Can you provide more programming language examples #21

Closed BuGTEa closed 4 years ago

BuGTEa commented 4 years ago

I just use example in https://github.com/kataras/iris/blob/master/_examples/websocket/basic/server.go

After run this server, I cannot access from python script.

The Python Script:

from websocket import create_connection
ws = create_connection("ws://127.0.0.1:8080/echo?X-Websocket-Header-X-Username=ok&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjozMjEzMjF9.8waEX7-vPKACa-Soi1pQvW3Rl8QY-SUFcHKTLZI4mvU")
print("Sending 'Hello, World'...")
ws.send("Hello, World")
print("Sent")
print("Receiving...")
result =  ws.recv()
print("Received '%s'" % result)
ws.close()

And the result shows that script can establish a connection, but when the client begins to receive , it shows that "WebSocketConnectionClosedException: Connection is already closed."

This problem also happens when I serve "./broswer/index.html" at another port using another web quick server (the index.html file has been modified so that the websocket port is still the same as server-side, that is, 8080.), it shows that

neffos.min.js:1 WebSocket connection to 'ws://0.0.0.0:8080/echo?X-Websocket-Header-X-Username=jhi&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjozMjEzMjF9.8waEX7-vPKACa-Soi1pQvW3Rl8QY-SUFcHKTLZI4mvU' failed: Error during WebSocket handshake: Unexpected response code: 403

So what should I do? And can you help me with a python websocket client script? Because I will use python script to listen and handle the websocket broadcasting message. Thank you.

BuGTEa commented 4 years ago

Update: I have resolve the second question (different port shows 403 error) using https://github.com/kataras/neffos/issues/11.

The problem now is how to connect to "namespace". Because other language using "/{namespace}" in URL to define different namespace, but neffos's namespace doesn't seem like performing in this form.

kataras commented 4 years ago

Hello @BuGTEa,

So far we have Go, Browser & Nodejs (Typescript) clients, from there you can retrieve information about how a neffos client should communicate with the server. Could you please upload your python neffos client somewhere so I can take a look and provide you more assistance about your issue?

Thanks, Gerasimos Maropoulos

kataras commented 4 years ago

@BuGTEa You are invited to https://github.com/neffos-contrib/python-client