有没有现成的应用程序可以重播 tcp 数据包?
我正在使用一台第三方设备,该设备打开一个 TCP 端口,一次只允许一个连接。如果我的应用程序连接到该端口,则所有其他连接都会被拒绝。
我想找到一个基本上连接到此端口的应用程序,然后允许其他人在不同的端口上连接到它。 从设备端口发送的任何数据都会重新广播到任何连接的客户端。
我知道如何编写这样的应用程序,但似乎其他人已经想到并编写了它并编写了它。共享,我可以避免花时间写它。
基本上代码是:
1)启动一个tcp套接字服务器,绑定到TO_PORT(客户端连接到此) 2)作为客户端连接到DEVICE_IP:DEVICE_PORT 3) 当数据从DEVICE_IP:DEVICE_PORT读入缓冲区时,缓冲区内容被重新发送到每个连接的客户端。 4) 使其成为一个稳定、可运行的程序的其他一切。
这是针对 Windows 的,我希望它不需要安装 java。
我的谷歌技能让我失败了。
有人知道这样的应用程序吗?
I am working with a 3rd party device which opens a tcp port that only allows one connection at a time. If my app connects to the port, all other connections are denied.
I'd like to find an app that basically connects to this port, then allows others to connect to it on a different port.
Any data sent out of the device's port is then rebroadcast to any connected client.
I know how to write such an app, but it seems like it would be something someone else has already thought off and written it & shared, and I could avoid taking the time to write it.
basicaly code would be:
1) start a tcp socket server, binding to TO_PORT (clients connect to this)
2) connect as a client to DEVICE_IP:DEVICE_PORT
3) when data is read into a buffer from DEVICE_IP:DEVICE_PORT, the buffer content is resent to each connected client.
4) everything else that makes it a stable, working program.
This is for windows, and I'd prefer it not require a java install.
My google skills have failed me.
Anyone know of such an app?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于您来说这不是一个完整的解决方案,但可能会很有趣,
http://www.codeproject。 com/KB/IP/serversocket.aspx
http://www.codeproject.com/KB/IP/UniversalTCPSocketClass.aspx
Not a complete solution for you, but might be interesting, though
http://www.codeproject.com/KB/IP/serversocket.aspx
http://www.codeproject.com/KB/IP/UniversalTCPSocketClass.aspx
我想我会回答我自己的问题。
我自己实施了该解决方案。
我的解决方案的要点:
一个名为 IPClient 的类,它包装了一个 TcpClient 实例,使用调用 TcpClient.BeginConnect、BeginRead 等的异步模型。它有一个计时器,用于在失去连接时重新连接。
这是连接到设备的类。
它的公共接口看起来像这样:
要打开允许其他客户端连接的端口,我使用了这个库: http://codeproject.com/KB/IP/BasicTcpServer.aspx 并对其进行了一些修改。
它的工作是打开一个端口,接受连接,并执行以下操作:
我将省略其余无聊的细节,但要说这并不“太难”,最终我不得不自己动手。
命令行用法:myapp.exeremote_addrremote_portlisten_portpsuedocode
/我的程序主要思想:
Guess I'll answer my own question.
I implemented the solution my self.
Key points to my solution:
A class named IPClient which wraps up a TcpClient instance, uses async model of calling TcpClient.BeginConnect, BeginRead, etc. It has a Timer used for reconnecting if it loses connection.
This is the class that connects to the device.
It's public interface would look something like this:
To open the port that would allow other clients to connect, I used this library: http://codeproject.com/KB/IP/BasicTcpServer.aspx and modified it a bit.
It's job was to open a port, accept connections, and do the following:
I'll leave out the rest of the boring details, but say it wasn't "too hard", and eventually I just had to roll my own.
command line usage: myapp.exe remote_addr remote_port listen_port
psuedocode/main idea of my program main: