/// <summary> /// 发送UDP广播给局域网内某一客户端表明自己在线 /// </summary> /// <param name="ipAddress">要发送到的地址</param> /// <param name="ping">之前收到的ping字符串</param> protected void StartAckUDPBroadcast(IPAddress ipAddress, string ping) { string protocalText = protocalHandler.Pack("ackaddr"); protocalText = protocalHandler.Append(protocalText, "tcpport", PortTCPListener.ToString()); protocalText = protocalHandler.Append(protocalText, "udpport", PortUDPListener.ToString()); protocalText = protocalHandler.Append(protocalText, "ping", ping); startUDPSend(protocalText, ipAddress); }
/// <summary> /// 发送UDP广播给局域网内客户端表明自己刚上线或刷新在线好友 /// </summary> /// <param name="ipAddress">要发送到的地址</param> protected void StartLoginUDPBroadcast(IPAddress ipAddress = null) { string protocalText = protocalHandler.Pack("update"); protocalText = protocalHandler.Append(protocalText, "tcpport", PortTCPListener.ToString()); protocalText = protocalHandler.Append(protocalText, "udpport", PortUDPListener.ToString()); Random rnd = new Random((int)DateTime.Now.Ticks); pingString = rnd.Next(0x7FFF).ToString(); protocalText = protocalHandler.Append(protocalText, "ping", pingString); pingMillis = DateTime.Now.Millisecond; if (ipAddress != null) { startUDPSend(protocalText, ipAddress); } else { startUDPSend(protocalText); } }