C# TcpClient Connect 先连接
我们有两个或多个程序实例(“节点”)通过 TCP 相互连接。我们的实现如下:
// 1. Connect
TcpClient connection;
while(true){
try
{
connection = new TcpClient("localhost", ((Port)Port).Value);
}
catch(SocketException/* Exception*/)
{
continue;
}
break;
}
// use the connection
这是并行发生的。首先连接的节点被视为它所连接的节点的父节点。我们想利用这个属性来生成生成树。 我们如何找出哪个节点首先连接,因为连接的唯一方法是调用 TcpClient 的构造函数?我们在哪里可以找到有关连接的更多信息?
请注意,出于测试目的,我们在一台计算机上使用多个端口。它应该可以通过互联网在不同的机器之间工作。
We have two or more instances ("Nodes") of a program connecting to eachother over TCP. We have implemented it as follows:
// 1. Connect
TcpClient connection;
while(true){
try
{
connection = new TcpClient("localhost", ((Port)Port).Value);
}
catch(SocketException/* Exception*/)
{
continue;
}
break;
}
// use the connection
This happens in parallel. The node that connects first is considered the parent of the node that it connects to. We want to use this propery to generate a spanning tree.
How do we find out which node connected first, seeing as the only way to connect is to call TcpClient's constructor? Where do we find additional information about the connection?
Note that for testing purposes we use several ports on one machine. It should work between different machines over the internet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法从客户端代码中确定这一点。
只有服务器可以确定这一点。并且只有服务器可以构建您指定的树。
如果您编写或有权修改服务器代码,您应该将其发布,以便获得进一步的帮助。
There's no way you can determine that from the client code.
Only the server can determine that. And only the server can build the tree you specified.
If you wrote or have access to modify the server code, you should post it so that you could get further help.