热点问答 - longcnn/websocketd_CN GitHub Wiki
I'm not the developer, but AFAIK, you'd be limited by the Server's RAM. Every opened connection would fork a process. So, if you're writing your server in e.g. C, this could be quite small. If you're using something like Perl (as i am), or PHP, this oculd be around 5MB to 10MB.
Not the developer, but it should be absolutely minimal, once the connection is established. The initial connection might take some milliseconds, because websocketd will have to fork of a process and start your server process.
You can use escape codes. Since you'll most likely be sending from Javascript, you can either wrap your output with JSON.stringify("first line\nsecond line")
or escape("first line\nsecond line")
. In your application code, you'll need to JSON.parse(msg)
or unescape(msg)
respectively upon receiving a message.
I've tried catching HUP, TERM and INT, and none of them seem to be sent to my program when I disconnect teh websocket. But I have to do some clean-up before exiting, so what can I do?
- The answer was simpler than I thought: websocketd simply closes STDIN, so the while () loop ends, and the program simply exits.
I connected to the websocket, and put my phone in airplane mode. The browser detects this immediately and shows an unclean disconnect, but my server program just lingers on. Implementing some last-time-I-received-data scheme would be trivial, but I am wondering if there's some inactivity timeout built-in?
- and the instant I submitted this last paragraph, I actually did get a timeout. After 17 minutes.