TooTallNate / Java-WebSocket

A barebones WebSocket client and server implementation written in 100% Java.
http://tootallnate.github.io/Java-WebSocket
MIT License
10.48k stars 2.58k forks source link

Error in 'ChatServer' example? #581

Closed martin-mucha closed 6 years ago

martin-mucha commented 6 years ago

I wrote prototype app, 99% the same. When I start server, and connect to it with client and then terminate server via stop() method, client connection (probably) will still hold respective port open (netstat -anp still reports it, but without associated process). Only after some time (tens of seconds) it's released.

Looping over opened connections and closing them before calling stop() fixes this issue, and immediately after server stop port is not used as expected.

I believe, it what I'm saying is correct, that this should be presented in example.

Thanks.

marci4 commented 6 years ago

Hello @mmucha-redhat,

could you please use the template for your bug report.

Right now I do not understand what you are doing and what you are expecting.

Greetings marci4

martin-mucha commented 6 years ago

There isn't an error. I was just a suggesting to close all connections before closing server in your demo ChatServer implementation, since otherwise it does not close port immediately on linux.

marci4 commented 6 years ago

Sorry to post on your closed issue!

This is not how the closing handshake works for the RFC 6455. A connection is closed when the endpoints receives a close frame. The websocket server is sending these frames during stop(), which he has to receive to close the connection!

Greetings marci4

martin-mucha commented 6 years ago

Sorry about this report; examining stop method it indeed closes all connections. However, on my env, it does not close port if any connection is opened before calling stop. And calling Websocket.stop(going_away) myself before closing WebSocketServer 'seemed' to remove this issue.

I might be wrong on that, I saw issue just a few times. I'll try to reproduce again, and if I do, I'll post proper bug report. With this one, I just thought there is error in example, which there isn't.