简体   繁体   English

与服务器建立新连接时得到通知

[英]Get notified when new connection is established with server

I am using the Lidgren library in order to communicate strings throw computers over network. 我正在使用Lidgren库 ,以便通过网络通信字符串抛出计算机。 I can get notified when a client disconnects from the server but I can not when a client connects. 当客户端与服务器断开连接时,我会收到通知,但是当客户端连接时,我不会收到通知。 I tried this piece of code running in a different thread : 我尝试了在不同线程中运行的这段代码:

 static void connectionCheck()
    {
        if (server.ConnectionsCount != con)
        {

            for (int i = con; i < s_server.Connections.Count; i++)
            {
                Console.WriteLine(server.Connections[i].Peer.Configuration.LocalAddress.ToString() + " connected");
            }
            con = server.ConnectionsCount;
        }
        Thread.Sleep(1);
        connectionCheck();
    }

where con is the old number of connections. 其中con是旧的连接数。 The only output I get is 0.0.0.0 connected after the newly connected client sends a message. 新连接的客户端发送消息后,我得到的唯一输出是0.0.0.0 connected Why isn't this working and how can I get notified when a new connection is established? 为什么这不起作用?建立新连接后如何通知我?

Call ReadMessage() on s_server; 在s_server上调用ReadMessage(); when you receive a message of type StatusChanged, examine the first byte, it holds a NetConnectionStatus enum - if it's "Connected" then a remote peer just established a connection to this peer. 当您收到类型为StatusChanged的消息时,请检查第一个字节,其中包含一个NetConnectionStatus枚举-如果它是“ Connected”,则远程对等方刚刚建立了与该对等方的连接。

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

相关问题 收到新邮件时,如何通过C#代码由Microsoft Exchange Server通知? - How to get notified by Microsoft Exchange Server in a C# code when a new mail is reveived? 检查是否建立了与IRC服务器的连接 - Checking if a connection to an IRC server is established 将新文件添加到 Google 云端硬盘时,FileSystemWatcher 不会收到通知 - FileSystemWatcher does not get notified when a new file is added to Google Drive 已建立的连接被服务器中止 - SFTP 服务器 - An established connection was aborted by the server - SFTP Server c# : 无法建立与服务器的连接 - c# : A connection with the server could not be established 尝试从 android 应用程序登录到我的服务器时出现“无法建立 ssl 连接”或“SSL 握手中止” - Getting "The ssl connection could not be established" or "SSL handshake aborted" when trying to log in from android app to my server 更改ObservableCollection时收到通知 - Get notified when ObservableCollection is changed 当变量改变时得到通知 - Get notified when a variable changed WebDav-收到通知后仅收到“新”邮件 - WebDav - Get “only” new mail after notified 当 ActiveMQ 中有新消息时,我们可以使用 HttpClient (SocketsHttpHandler) 在 TCP/IP 的情况下自动获得通知吗? - Can we use HttpClient (SocketsHttpHandler) to get notified automatically like in case of TCP/IP when there is a new message in ActiveMQ?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM