开发者

C# TcpClient Connect first to connect

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜