Ejemplo n.º 1
0
            /// <summary>
            /// 发送一条Udp消息
            /// </summary>
            /// <param name="ip">Ip.</param>
            /// <param name="port">Port.</param>
            /// <param name="msg">Message.</param>
            public static void UdpSend(string ip, int port, byte[] msg, IPType ipType = IPType.IPv4)
            {
                if (udpHandler == null)
                {
                    udpHandler = new Udp(7575, ipType);
                }

                udpHandler.SendTo(new System.Net.IPEndPoint(System.Net.IPAddress.Parse(ip), port), msg);
            }
Ejemplo n.º 2
0
            /// <summary>
            /// 发送一条Udp消息
            /// </summary>
            /// <param name="target">Target.</param>
            /// <param name="msg">Message.</param>
            public static void UdpSend(System.Net.EndPoint target, byte[] msg, IPType ipType = IPType.IPv4)
            {
                if (udpHandler != null)
                {
                    udpHandler = new Udp(7575, ipType);
                }

                udpHandler.SendTo(target, msg);
            }
Ejemplo n.º 3
0
            /// <summary>
            /// 启动Udp服务器
            /// </summary>
            /// <returns><c>true</c>, 启动成功, <c>false</c> 没启动成功.</returns>
            /// <param name="port">端口.</param>
            /// <param name="ResponseCallBack">接收到消息的回掉方法 接受传入Endpoint发送源和string消息 返回string消息返回string类型返回值直接回复给客户端 如果为null则不回复.</param>
            /// <param name="iPType">IPv4 或 IPv6.</param>
            /// <param name="bufferSize">缓冲区尺寸.</param>
            public static bool ServerUdpStart(Action <System.Net.EndPoint, byte[]> ResponseCallBack = null, int port = 8085, IPType iPType = IPType.IPv4, int bufferSize = 1024)
            {
                try
                {
                    udpHandler = new Udp(port, iPType, ResponseCallBack, bufferSize);

                    udpHandler.runServer();

                    Logger.Log("UDP 服务端 已成功启动!端口:" + port + "");
                    //Logger.Log("欢迎来到微服务器,本SDK的使用详情请登录http://src.pub/查看");

                    return(true);
                }
                catch (Exception e)
                {
                    Logger.LogError("UDP Start Error" + e.Message);

                    return(false);
                }
            }