Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can this server push message to client ? #4

Open
PudgeMa opened this issue Jul 23, 2017 · 3 comments
Open

can this server push message to client ? #4

PudgeMa opened this issue Jul 23, 2017 · 3 comments

Comments

@PudgeMa
Copy link

PudgeMa commented Jul 23, 2017

I want to make a Tcp Server that can push message to client, and I'm worry about how to save and mark every SocketChannel of client.
does your code have this function ? thanks.

@jjenkov
Copy link
Owner

jjenkov commented Jul 23, 2017 via email

@PudgeMa
Copy link
Author

PudgeMa commented Jul 27, 2017

@jjenkov yeah. I have the same idea. I think it may be difficult to remove socket from the map when the socket disconnects with server, so the heartbeat may be need to detect that.

@jjenkov
Copy link
Owner

jjenkov commented Aug 1, 2017

Actually, this server already assigns an ID to the sockets and puts them into a Map. It also removes them again when the sockets are closed. Look at this code from the SocketProcessor:

    if(socket.endOfStreamReached){
        System.out.println("Socket closed: " + socket.socketId);
        this.socketMap.remove(socket.socketId);
        key.attach(null);
        key.cancel();
        key.channel().close();
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants