简体   繁体   English

多端口Netty套接字服务器

[英]Multiport Netty Socket Server

I am attempting to develop the following usecase with Netty: 我正在尝试使用Netty开发以下用例:

  1. Client connects to an intermediary server on (port 8900). 客户端连接到(端口8900)上的中间服务器。
  2. Client sends a Processor request with a configuration to another machine. 客户端将具有配置的处理器请求发送到另一台计算机。
  3. 3rd machine, based on configuration, starts a Processor. 第三台计算机根据配置启动处理器。
  4. Processor connects to the same server which started the processor based on the port identified in the configuration (port 8901, for example). 处理器基于配置中标识的端口(例如,端口8901)连接到启动处理器的同一服务器。
  5. Server now binds Client and Processor based on matching unique hashes shared between the two. 服务器现在基于两者之间共享的唯一哈希值绑定客户端和处理器。
  6. New Processors are created for each new Client connection. 为每个新的客户端连接创建新的处理器。

The client connection is not a problem. 客户端连接不是问题。 I have a ClientHandler which handles those requests. 我有一个ClientHandler来处理这些请求。 But I am having a problem registering the ProcessorHandler (which must be bound dynamically based on the configuration sent from the client) and made to serve the specific client. 但是我在注册ProcessorHandler时遇到了问题(必须根据从客户端发送的配置动态绑定ProcessorHandler)并使其服务于特定的客户端。

Any help would be much appreciated as I am currently stumped on how, from ClientHandler, once the configuration for a processor is sent, I could start a new server socket on the server and link the client to it's processor. 任何帮助将不胜感激,因为我目前对如何从ClientHandler中获取关于处理器配置的发送方法感到困惑,我可以在服务器上启动新的服务器套接字并将客户端链接到其处理器。

Client and processor share a unique hash number which can be used to identify which processor should server which client. 客户端和处理器共享唯一的哈希码,该哈希码可用于标识哪个处理器应为哪个客户端提供服务。

I've basically been using Netty HexProxy Example idea, but instead of a client socket, I need another server socket to serve the processor. 我基本上一直在使用Netty HexProxy Example的想法,但是我需要一个服务器套接字来代替处理器,而不是客户端套接字。 I was thinking of linking the two by either adding a handler to the other's pipe or doing something similar to Netty SecureChat Example . 我正在考虑通过将处理程序添加到对方的管道或执行类似于Netty SecureChat Example的操作链接两者

By re-imagining the scenario I was able to solve this problem. 通过重新构想场景,我能够解决此问题。

Instead of thinking of a Client as a client and a Processor as a server serving the requests of a specific client I treat both as clients connecting to a chat server (the intermediary server). 我将客户端视为连接到聊天服务器(中间服务器)的客户端,而不是将客户端视为客户端,将处理器视为服务于特定客户端请求的服务器。

Arbitrary server ports are established by sending the bootstrap into a HandshakeHandler which binds and syncs ports which are not currently bound. 通过将引导程序发送到HandshakeHandler中来建立任意服务器端口,该HandshakeHandler绑定并同步当前未绑定的端口。

It is also the HandshakeHandler which, via the unique hash, connects Clients and Processors into a specific ChannelGroup and reconfigures channel pipelines for each channel as required (removing itself once the handshake between Client and Processor have completed successfully). 也是HandshakeHandler,它通过唯一的哈希将客户端和处理器连接到特定的ChannelGroup中,并根据需要为每个通道重新配置通道管道(一旦Client和Processor之间的握手成功完成,则将其自身删除)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM