是否有可能“接力”的插座?有可能、插座

由网友(你给的伤数不清)分享简介:我不知道这有可能传递一个套接字对象在C#或Java的? (preferably C#)I was wondering it it was possible to relay a socket object in either C# or Java? (Preferably C#)我有很多的小程序我做的和东道主他们在...

我不知道这有可能传递一个套接字对象在C#或Java的? (preferably C#)

I was wondering it it was possible to relay a socket object in either C# or Java? (Preferably C#)

我有很多的小程序我做的和东道主他们在我的家用电脑,但我的电脑是一台路由器的后面,所以我每次都我想打一个新的应用程序转发端口在我的路由器。那么,有没有一种方法来发送一个TCP连接到另一个应用程序在同一台计算机上?比如我得到的文本的第一行的连接是 RELAY :: 21005 这会再往前就是端口本地主机:21005

I have lots of little programs i make and host them on my home pc, but my pc is behind a router, so i have to forward a port on my router every time i want to make a new application. So is there a way to send a tcp connection to another application on the same computer? for instance i get a connection in with the first line of text being RELAY::21005 which would then forward that port to localhost:21005 ?

任何帮助,教程,code段将是非常美联社preciated。谢谢! :)

Any help, tutorials, code snippets would be much appreciated. Thank you! :)

推荐答案

您可能会与你所建议的解决方案面临的一个问题(第一行标识目标端口)是,你必须改变所有的客户端程序来发送第一线。这很容易让你写自己,但不是那么方便的程序,如果你想连接到PC的Web服务器或ssh守护进程等,这是当然不是不可能,但确实让人很难。

One problem you might face with your suggested solution (first line identifies target port) is that you'll have to change all of your client programs to send that first line. That's easy for programs you've written yourself but not so convenient if you want to connect to your PC's web server or ssh daemon etc. It's not impossible of course, but does make it hard.

我会建议在两个端口的路由服务器监听 - 一个控制端口和一个正常的端口(我想不出一个更好的名字的那一刻)。你会发送控制消息的控制端口来指示,直至另行通知重定向的普通端口到端口NNNN对所有传入连接。这避免了操作的客户端协议。

I'd suggest your routing server listens on two ports - a control port and a "normal" port (I can't think of a better name at the moment). You would send control messages to the control port to indicate "until further notice redirect all incoming connections on the normal port to port nnnn". That avoids having to manipulate client protocols.

我不知道足够的C#提供咨询有关C#的解决方案,但在Java我只是做这样的事情:

I don't know enough C# to provide advice about a C# solution, but in Java I'd simply do something like:

while (true) {
    acceptConnectionOnNormalPort()
    connectToTargetPort()
    startThreadCopyingDataFromAcceptedPortToTargetPort()
    startThreadCopyingDataFromTargetPortToAcceptedPort()
}

您会无法,很容易扩展到数千个连接...

You'd not be able to scale that easily into thousands of connections...

阅读全文

相关推荐

最新文章