Reputation: 23
I want to create a server to let clients connect to, so from this point, it's a server only. But, at the same time, this server - let's call it "Server A" - it need to connect to another server (I'll call it "Server B") to report its own information, not as a proxy that route data from client to "Server B", only report it's information like "I'm still online".
So, many clients will connect to "Server A", and "Server A" will connect to "Server B" as a client. How can I do this by using Netty?
I read netty's proxy example, but I think the proxy server is create a client when it receive a client's connection temporary. But I need a dedicate client role for this purpose on "Server A", not like that. Help me, thanks.
Upvotes: 0
Views: 747
Reputation: 7973
You can bootstrap your client to Server B in the channelActive
or any other method of your Server A handler. Then once the client bootstrap is successful you can send any message to your Server B using the client.
An example is here: https://github.com/normanmaurer/netty-in-action/blob/2.0-SNAPSHOT/chapter8/src/main/java/nia/chapter8/BootstrapSharingEventLoopGroup.java
Instead of setting a childHandler
for your server, you can set the handler
for the ServerChannel
. Then its methods would be called only once for the server and not for each client connection.
Upvotes: 2