Closed fefe78 closed 9 years ago
send: '\x88\x822\xe0\xee21\x08' => this is automatically sent
websocket client sent the "close" frame and the connection was lost. I didn't figure out why client sent such a frame.
Could you upload the source code? and which websocket server are you using?
Hi liris,
thanks for reply. Here is the minimized code:
import socket
import websocket
import threading
import time
import sys
import datetime
import json
import urllib2
def log(string):
print str(datetime.datetime.now().time()) + " => " + string
def on_message(ws, message):
buffer=message
while len(buffer) > 12:
datalength=int(buffer[0:4])
if len(buffer) < datalength + 4:
return #//wait for more data
data = buffer[4:datalength + 4]
if len(data) != datalength:
break; #malformed message
log(data)
buffer = buffer[datalength + 4:]
def on_error(ws, error):
print error
def on_close(ws):
log( "### closed ###")
def sendKeepAlive():
log("sending KeepAlive")
ws.send("0 0 0 1 0\n\0")
log("KeepAlive sent")
def login(ws):
log("sending login...")
ws.send("hello fcserver\n\0")
ws.send("1 0 0 20071025 0 guest:guest\n\0")
t = threading.Timer(15.0, sendKeepAlive)
t.start()
if __name__ == "__main__":
try:
websocket.enableTrace(True)
ws = websocket.WebSocketApp("ws://xchat9.myfreecams.com:8080/fcsl",
on_message = on_message,
on_error = on_error,
on_close = on_close)
ws.on_open = login
ws.run_forever(ping_interval=100)
except KeyboardInterrupt:
log("Ok ok, quitting")
t.cancel()
ws.close()
sys.exit(1)
Essentially I connect to the websocket server defined with the websocket app.. send a hello packet and a login packet.. then a burst of data starting to come.. After 45 secs you should see the close frame.
thanks.
Source code looks OK. Please give me information of stack trace when the on_close is called.
def on_close(ws):
import traceback
traceback.print_stack()
log( "### closed ###")
Here it is... anyway I'm using python 2.7 on raspberrypi 3.12.28+ ... if the problem could be environment related.. Anyway you can run the code above by yourself.. it should work..
send: '\x88\x82\xd1aNB\xd2\x89'
File "MFC_socket_test.py", line 57, in <module>
ws.run_forever(ping_interval=100)
File "/usr/local/lib/python2.7/dist-packages/websocket/_app.py", line 210, in run_forever
*self._get_close_args(close_frame.data if close_frame else None))
File "/usr/local/lib/python2.7/dist-packages/websocket/_app.py", line 231, in _callback
callback(self, *args)
File "MFC_socket_test.py", line 34, in on_close
traceback.print_stack()
09:55:24.532420 => ### closed ###
It seems websocket servet sent the "close" frame and the client reply it. Can you confirm the server sent it?
Sorry for delay.. It was my fault.. Not sending correctly the keppalive frame to server.. so I was kicked out. Sorry for that. Thanks for help.
Hi,
I'm trying to deal with an external websocket server (not mine), but what is happening is that after 45 seconds the socket send something to the server, and the server close the connection down (maybe it does not recognize the data sent). What the socket is automatically sending? No ping is set. I send a Keepalive to the server, but with or without, the behaviour is the same.
Here is an example: