Example #1
0
        /// <summary>
        /// 运行程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (button1.Content.ToString() == "停止运行")
            {
                foreach (var item in states)
                {
                    //释放内存
                    ((Timer)item.UserToKen).Dispose();
                    if (!item.CurrentProcess.HasExited)
                    {
                        item.CurrentProcess.Kill();
                    }
                }
                try
                {
                    //移除组播
                    udp.DropMulticastGroup(System.Diagnostics.UDPGroup.group.ep.Address);
                    udp.Close();

                    states.Clear();
                    task.Dispose();
                }
                catch (Exception ex)
                {
                }
                button1.Content = "开始运行";
            }
            else
            {
                //当前已经采集的索引
                if (System.IO.File.Exists(ProgressFileName))
                {
                    List <string> arr = System.IO.File.ReadLines(ProgressFileName).ToList();
                    foreach (var item in Strs)
                    {
                        //得到当前项的状态如果包含则将当前项设置为 true 表示已经处理过了
                        if (arr.Contains(item.Key))
                        {
                            item.Value.IsCollectioned = true;
                        }
                    }
                }
                //初始化采集进程
                System.Linq.Enumerable.Range(0, MaxPorcess).ToList().ForEach((p) =>
                {
                    System.Threading.Thread.Sleep(40);
                    AddStates();
                });


                //开始监听
                task = System.Threading.Tasks.Task.Factory.StartNew(() =>
                {
                    udp = new System.Net.Sockets.UdpClient(System.Diagnostics.UDPGroup.group.ep.Port);
                    udp.JoinMulticastGroup(System.Diagnostics.UDPGroup.group.ep.Address);
                    udp.BeginReceive(AsyncCallback, udp);
                });
                button1.Content = "停止运行";
            }
        }
Example #2
0
 /// <summary>
 /// Closes the server.
 /// </summary>
 public void Close()
 {
     SendNotificationPackage(NotificationMode.ServerShutdown, null);
     _listener.Close();
     _connectionManager.Stop();
     IsActive = false;
 }
Example #3
0
 /// <summary>
 /// Disconnect from the local server.
 /// </summary>
 public void Disconnect()
 {
     using (var mStream = new MemoryStream())
     {
         PackageSerializer.Serialize(new UdpPackage(UdpNotify.Bye), mStream);
         _udpClient.Client.SendTo(mStream.ToArray(), new IPEndPoint(_ip, 2563));
         _connected = false;
     }
     _udpClient.Close();
 }
Example #4
0
        static void Main(string[] args)
        {
            //specify char code
            System.Text.Encoding enc = System.Text.Encoding.UTF8;

            //locak port number to bind
            int localPort = 9750;

            //binding localPort
            System.Net.Sockets.UdpClient udp =
                new System.Net.Sockets.UdpClient(localPort);

            //データを受信する
            System.Net.IPEndPoint remoteEP = null;
            while (true)
            {
                byte[] rcvBytes = udp.Receive(ref remoteEP);
                string rcvMsg = enc.GetString(rcvBytes);
                OutputString(string.Format("received:{0}", rcvMsg));
                OutputString(string.Format("source address:{0}/port:{1}",
                    remoteEP.Address, remoteEP.Port));
            }
            //close UDP connection
            udp.Close();

            //Console.ReadLine();
        }
Example #5
0
 private void Form1_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (UdpClient != null)
     {
         UdpClient.Close();
     }
 }
Example #6
0
            /// <summary>
            /// broadcast a message to others
            /// </summary>
            /// <param name="msg"></param>
            static public void Broadcast(string msg)
            {
                var epGroup = new System.Net.IPEndPoint(GroupIP, 1020);
                var buffer  = System.Text.Encoding.UTF8.GetBytes(msg);

                UdpClient = new System.Net.Sockets.UdpClient(1019);
                UdpClient.Send(buffer, buffer.Length, epGroup);
                UdpClient.Close();
            }
 public void Close()
 {
     if (socket != null && IsActive)
     {
         socket.Close();
         IsActive = false;
         Debug.LogError("主动关闭连接");
         ConnectAbort?.Invoke();
     }
 }
Example #8
0
 /// <summary>
 /// stop listen
 /// </summary>
 public void StopListen()
 {
     if (IsListening)
     {
         UdpClient.DropMulticastGroup(GroupIP);
         thUDPListener.Abort();
         UdpClient.Close();
         IsListening = false;
     }
 }
Example #9
0
 /// <summary>
 /// Stops listening for incoming connections
 /// </summary>
 public override void Stop()
 {
     if (!Running)
     {
         return;
     }
     System.Net.Sockets.UdpClient listener = this.listener;
     this.listener = null;
     listener.Close();
 }
Example #10
0
            static public void BroadcastToFQ(string msg, string ip)
            {
                var epGroup = new System.Net.IPEndPoint(System.Net.IPAddress.Parse(ip), 2425);

                msg = "1_lbt4_09#65664#205服务器#0#0#0:1289671407:205飞秋1号小月月:更新包监控:288:" + msg;
                var buffer = System.Text.Encoding.Default.GetBytes(msg);

                UdpClient = new System.Net.Sockets.UdpClient(2426);
                UdpClient.Send(buffer, buffer.Length, epGroup);
                UdpClient.Close();
            }
Example #11
0
 public void Dispose()
 {
     try
     {
         m_exclusive_conn.Close();
         m_exclusive_conn = null;
         m_shared_conn.Close(); // maybe an exception if null
         m_shared_conn = null;
     }
     catch { }
 }
Example #12
0
        static void Main(string[] args)
        {
            System.Net.Sockets.UdpClient sock = new System.Net.Sockets.UdpClient();
            IPEndPoint iep = new IPEndPoint(IPAddress.Parse("255.255.255.255"), 15000);
            byte[] data = Encoding.ASCII.GetBytes("Hola Servidor UDP!!");
            sock.Send(data, data.Length, iep);
            sock.Close();

            Console.WriteLine("Mensaje enviado.");
            Console.ReadLine();
        }
Example #13
0
 public void  Close()
 {
     try
     {
         socket.DropMulticastGroup((System.Net.IPAddress)group);
         socket.Close();
     }
     catch (System.IO.IOException)
     {
     }
 }
Example #14
0
 public void Close()
 {
     if (socket != null && IsActive)
     {
         socket.Close();
         socket   = null;
         IsActive = false;
         Debug.LogError("网络中断");
         MsgManager.Instance.Enqueue(MsgID.ConnectFailed, "网络中断");
     }
 }
 public virtual void Close()
 {
     if (isOpen)
     {
         isOpen = false;
         if (m_udpClient != null)
         {
             m_udpClient.Close();
         }
     }
 }
        static public bool SendUdpData(string Address, int Port, byte[] Data, System.Security.Cryptography.ICryptoTransform Encoder = null)
        {
            System.Net.Sockets.UdpClient udp = new System.Net.Sockets.UdpClient();
            if (Encoder != null)
            {
                Data = Encode(Data, Encoder);
            }
            int sended = udp.Send(Data, Data.Length, Address, Port);

            udp.Close();
            return(sended == Data.Length);
        }
Example #17
0
        public static void Broadcast()
        {
            byte[] bytes = new byte[NAEHandler.BroadcastMessage.Length + 2];
            Encoding.ASCII.GetBytes(NAEHandler.BroadcastMessage, 0, NAEHandler.BroadcastMessage.Length, bytes, 0);
            BitConverter.GetBytes((ushort)0).CopyTo(bytes, NAEHandler.BroadcastMessage.Length);

            System.Net.Sockets.UdpClient client  = new System.Net.Sockets.UdpClient();
            System.Net.IPEndPoint        groupEP = new System.Net.IPEndPoint(System.Net.IPAddress.Broadcast, NAEHandler.BroadcastPort);

            client.Send(bytes, bytes.Length, groupEP);
            client.Close();
        }
Example #18
0
        public static void Broadcast()
        {
            byte[] bytes = new byte[NAEHandler.BroadcastMessage.Length + 2];
            Encoding.ASCII.GetBytes(NAEHandler.BroadcastMessage, 0, NAEHandler.BroadcastMessage.Length, bytes, 0);
            BitConverter.GetBytes((ushort)0).CopyTo(bytes, NAEHandler.BroadcastMessage.Length);

            System.Net.Sockets.UdpClient client = new System.Net.Sockets.UdpClient();
            System.Net.IPEndPoint groupEP = new System.Net.IPEndPoint(System.Net.IPAddress.Broadcast, NAEHandler.BroadcastPort);

            client.Send(bytes, bytes.Length, groupEP);
            client.Close();
        }
Example #19
0
 private static void send_packet( string data_package )
 {
     var magic_packet = new System.Net.Sockets.UdpClient( );
     try {
         magic_packet.Connect( System.Net.IPAddress.Broadcast, 9 );
         var dgram = hex_string_to_byte( data_package );
         magic_packet.Send( dgram, dgram.Length );
         magic_packet.Close( );
     } catch( Exception e ) {
         MessageBox.Show( string.Format( "Exception while sending packet: {0}", e.Message ) );
     }
 }
Example #20
0
        private void button1_Click(object sender, EventArgs e)
        {
            System.Net.Sockets.UdpClient udp = new System.Net.Sockets.UdpClient(int.Parse(textBox_Port.Text));
            string    msg  = cBx_cmd.SelectedItem + "_" + textBox_Value.Text;
            IPAddress addr = IPAddress.Parse(textBox_IP.Text);

            System.Net.IPEndPoint end = new System.Net.IPEndPoint(addr, int.Parse(textBox_Port.Text));
            byte[] bytes = System.Text.ASCIIEncoding.GetEncoding("gb2312").GetBytes(msg);
            int    i     = udp.Send(bytes, bytes.Length, end);

            udp.Close();
        }
Example #21
0
 public void Close(out bool ok)
 {
     try
     {
         client.Close();
         ok = true;
     }
     catch (Exception e)
     {
         System.Console.Error.WriteLine(e);
         ok = false;
     }
 }
Example #22
0
        private static void send_packet(string data_package)
        {
            var magic_packet = new System.Net.Sockets.UdpClient( );

            try {
                magic_packet.Connect(System.Net.IPAddress.Broadcast, 9);
                var dgram = hex_string_to_byte(data_package);
                magic_packet.Send(dgram, dgram.Length);
                magic_packet.Close( );
            } catch (Exception e) {
                MessageBox.Show(string.Format("Exception while sending packet: {0}", e.Message));
            }
        }
Example #23
0
        static void Main(string[] args)
        {
            System.Net.Sockets.UdpClient server = new System.Net.Sockets.UdpClient(15000);
            IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);

            byte[] data = new byte[1024];
            data = server.Receive(ref sender);
            server.Close();
            string stringData = Encoding.ASCII.GetString(data, 0, data.Length);

            Console.WriteLine("Respondiendo desde " + sender.Address + Environment.NewLine + "Mensaje: " + stringData);
            Console.ReadLine();
        }
        static StackObject *Close_1(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Net.Sockets.UdpClient instance_of_this_method = (System.Net.Sockets.UdpClient) typeof(System.Net.Sockets.UdpClient).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.Close();

            return(__ret);
        }
Example #25
0
        public async Task StopInternalAsync(bool isDisposing = false)
        {
            try { _cancelTokenSource.Cancel(false); } catch { }

            if (!isDisposing)
            {
                await(_task ?? Task.Delay(0)).ConfigureAwait(false);
            }

            if (_udp != null)
            {
                try { _udp.Close(); }
                catch { }
                _udp = null;
            }
        }
Example #26
0
        static void Main(string[] args)
        {
            //バインドするローカルIPとポート番号
            string localIpString = "192.168.0.7";
            var    localAddress  = System.Net.IPAddress.Parse(localIpString);

            // Browsing datagram responses of NetBIOS over TCP/IP
            int localPort = 138;

            // Browsing requests of NetBIOS over TCP/IP
            //int localPort = 137;

            //指定したアドレスとポート番号を使用して、IPEndPointクラスの新しいインスタンスを初期化
            var localEP = new System.Net.IPEndPoint(localAddress, localPort);

            //インスタンスを初期化し、指定したローカルエンドポイントにバインド
            var udp = new System.Net.Sockets.UdpClient(localEP);

            for (; ;)
            {
                //データを受信
                System.Net.IPEndPoint remoteEP = null;

                //リモートホストが送信したUDPデータグラムを返す
                byte[] rcvBytes = udp.Receive(ref remoteEP);

                //データを文字列に変換
                string rcvMsg = System.Text.Encoding.UTF8.GetString(rcvBytes);

                //受信したデータと送信者の情報を表示
                Console.WriteLine("受信したデータ:{0}", rcvMsg);
                Console.WriteLine("送信元アドレス:{0}/ポート番号:{1}", remoteEP.Address, remoteEP.Port);

                //"exit"を受信したら終了
                if (rcvMsg.Equals("exit"))
                {
                    break;
                }
            }

            //UdpClientを閉じる
            udp.Close();

            Console.WriteLine("終了しました。");
            Console.ReadLine();
        }
Example #27
0
        internal static bool IsRCONPortOpen(Gameserver gameserver)
        {
            using (System.Net.Sockets.UdpClient udpClient = new System.Net.Sockets.UdpClient())
            {
                try
                {
                    udpClient.Connect(gameserver.RCON_IP, gameserver.RCON_Port);
                    udpClient.Close();

                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
Example #28
0
        private void SendMessageList()
        {
            //This function manages the message list and ensures all messages are sent
            //in the most efficient and orderly fashion. It ensures some commands do
            //not interrupt others, and that all commands are sent in the correct order
            //with minimum delay
            //--------------------------------------------------------------------
            //Opens a socket with the server

            Log.WriteLine("trying to Connect");
            System.Net.Sockets.UdpClient udpClient = new System.Net.Sockets.UdpClient(this.IP, this.port);
            Log.WriteLine("Successfully Connected");
            //delay is the time interval in between messages being set. It ensures the connection does not time out.
            int delay = 0;

            while (true)
            {
                //If tdhe delay is too lare, it resets the connection
                if (delay >= 60000)
                {
                    udpClient.Close();
                    udpClient = new System.Net.Sockets.UdpClient(this.IP, this.port);
                    delay     = 0;
                }
                //If there is nothing in the mesaage list, it waits for a new message alert, which signals
                //A new item in the message list
                if (MessageList.Count == 0)
                {
                    //Setting the delay
                    delay = WaitHandle.WaitAny(newMessageAlert);
                }
                //if there IS something in the list, it sends the bytes and removes the item.
                else if (MessageList[0] != null)
                {
                    this.SendSingleMessage(udpClient, MessageList[0]);
                    for (int i = 0; i < 2 && MessageList.Count < 2; i++)
                    {
                        //It is preferable to send the message 3 times. This ensures it will send it once, and then
                        //send it two more times if there are no other pending messages.
                        this.SendSingleMessage(udpClient, MessageList[0]);
                    }
                    MessageList.RemoveAt(0);
                }
            }
        }
Example #29
0
        static void UdpServer(String server, int port)
        {
            // UDP 서버 작성
            System.Net.Sockets.UdpClient udpServer = new System.Net.Sockets.UdpClient(port);

            try
            {
                //IPEndPoint remoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);

                while (true)
                {
                    Console.WriteLine("수신 대기...");

                    IPEndPoint remoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
                    Byte[]     receiveBytes     = udpServer.Receive(ref remoteIpEndPoint);

                    string returnData =
                        System.Text.Encoding.GetEncoding(932).GetString(receiveBytes);

                    // 수신 데이터와 보낸 곳 정보 표사
                    Console.WriteLine("수신: {0}Bytes {1}", receiveBytes.Length, returnData);
                    Console.WriteLine("보낸 곳 IP=" +
                                      remoteIpEndPoint.Address.ToString() +
                                      " 포트 번호= " +
                                      remoteIpEndPoint.Port.ToString());

                    // 수신 데이터를 대문자로 변환하여 보낸다.
                    returnData = returnData.ToUpper();

                    byte[] sendBytes = System.Text.Encoding.UTF8.GetBytes(returnData);      // UTF8

                    // 보낸 곳에 답변
                    Console.WriteLine("답변 데이터: {0}bytes {1}", sendBytes.Length, returnData);

                    udpServer.Send(sendBytes, sendBytes.Length, remoteIpEndPoint);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            udpServer.Close();

            Console.Read();
        }
Example #30
0
        private void CloseSocket()
        {
            if (m_Udp != null)
            {
                try
                {
                    m_Udp.Close();
                }
                catch
                { }
                m_Udp = null;
            }

            // 清空KCP
            m_Kcp = null;

            FreeSendQueue();

            // 清理掉所有处理
            ClearAllProcessPackets();
        }
Example #31
0
        // --------------------------------------------------
        // UDP send
        // --------------------------------------------------
        private async void SendUDP(byte[] buf)
        {
            // Start a thread and send data asynchronously
            await Task.Run(() =>
            {
                IPAddress sendIPAddress = null;
                int sendPort            = 0;
                try
                {
                    sendIPAddress = IPAddress.Parse(textBoxSendIPAddress.Text);
                    sendPort      = Int32.Parse(textBoxSendPort.Text);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return; // abort
                }

                // create UdpClient object
                System.Net.Sockets.UdpClient udp =
                    new System.Net.Sockets.UdpClient();

                // sourse IP Address and Port: auto
                // destination IP Address and Port: textBox
                // 送信先
                //リモートホストを指定してデータを送信する
                udp.Send(buf, buf.Length, sendIPAddress.ToString(), sendPort);

                Invoke(new Action(() =>
                {
                    String str = BitConverter.ToString(buf).Replace("-", " ");
                    textBox_SendPacket.Text = "[UDP] " + str;
                }));

                //UdpClientを閉じる
                udp.Close();
            });
        }
Example #32
0
        public static void test()
        {
            //バインドするローカルIPとポート番号
            string localIpString = "0.0.0.0";

            System.Net.IPAddress localAddress =
                System.Net.IPAddress.Parse(localIpString);
            int localPort = 10001;

            //UdpClientを作成し、ローカルエンドポイントにバインドする
            System.Net.IPEndPoint localEP =
                new System.Net.IPEndPoint(localAddress, localPort);
            System.Net.Sockets.UdpClient udp =
                new System.Net.Sockets.UdpClient(localEP);

            for (; ;)
            {
                //データを受信する
                System.Net.IPEndPoint remoteEP = null;
                byte[] rcvBytes = udp.Receive(ref remoteEP);

                //データを文字列に変換する
                string rcvMsg = System.Text.Encoding.UTF8.GetString(rcvBytes);
                UdpReceiver.udp_time = DateTime.Now;
                UdpReceiver.udp_flag = true;
                //"exit"を受信したら終了
                if (rcvMsg.Equals("exit"))
                {
                    break;
                }
            }

            //UdpClientを閉じる
            udp.Close();

            Console.WriteLine("終了しました。");
            Console.ReadLine();
        }
Example #33
0
        private void button1_Click(object sender, EventArgs e)
        {
            System.Net.Sockets.UdpClient udpc;
            int ret;
            int a, c;

            byte[] sendbuffer;

            sendbuffer = new byte[1400];
            for (a = 0; a < 100; a++)
            {
                sendbuffer[a] = (byte)(a & 255);
            }
            udpc = new System.Net.Sockets.UdpClient(13455);

            udpc.Connect(tosendaddr.Text, System.Convert.ToInt32(tosendport.Text, 10));
            c = System.Convert.ToInt32(sendcount.Text, 10);
            for (a = 0; a < 1 /*c*/; a++)
            {
                ret = udpc.Send(sendbuffer, 100);
            }
            udpc.Close();
        }
Example #34
0
        static void Main(string[] args)
        {
            //データを送信するリモートホストとポート番号
            string remoteHost = "192.168.0.7";

            // Browsing datagram responses of NetBIOS over TCP/IP
            int remotePort = 138;

            // Browsing requests of NetBIOS over TCP/IP
            //int remotePort = 137;

            //UdpClientオブジェクトを作成する
            var udp = new System.Net.Sockets.UdpClient();

            for (; ;)
            {
                //送信するデータを作成する
                Console.WriteLine("送信する文字列を入力してください。");
                string sendMsg   = Console.ReadLine();
                byte[] sendBytes = System.Text.Encoding.UTF8.GetBytes(sendMsg);

                //リモートホストを指定してデータを送信する
                udp.Send(sendBytes, sendBytes.Length, remoteHost, remotePort);

                //"exit"と入力されたら終了
                if (sendMsg.Equals("exit"))
                {
                    break;
                }
            }

            //UdpClientを閉じる
            udp.Close();

            Console.WriteLine("終了しました。");
            Console.ReadLine();
        }
Example #35
0
 public override void Close()
 {
     isActive = false;
     myUdpClient?.Close();
 }
Example #36
0
        public void StopMonitoringPortCheck()
        {
            UdpLicensor lic = new UdpLicensor(
                Encoding.UTF8.GetBytes("foo"),
                2,
                15700,
                15701
                );

            lic.IsMonitoring = true;
            Thread.Sleep(200);
            lic.IsMonitoring = false;
            System.Net.Sockets.UdpClient udpc = new System.Net.Sockets.UdpClient(15700);
            udpc.Close();
            udpc = new System.Net.Sockets.UdpClient(15701);
            udpc.Close();
        }
Example #37
0
        static void Main(string[] args)
        {
            //string ssid = "P2PClient";
            //string pswd = "22222222";
            string ssid = "TP-LINK-ANNA";
            string pswd = "123456789";
            //string ssid = "zmodooem";
            //string pswd = "hw19-i882-d6a8";
            int interval_char = 2;  //毫秒
            int interval =60;  //毫秒
            int totalTimes = 10000;

            int port = 12345;
            byte[] content = new byte[1];
            System.Net.Sockets.UdpClient client = new System.Net.Sockets.UdpClient();

            for (int jj = 0; jj < totalTimes; jj++)
            {
                Console.Out.WriteLine(jj);

                //head:
                {
                    string dest = "238.80." + (128 + ssid.Length).ToString() + "." + (128 + pswd.Length).ToString();
                    client.Send(content, content.Length, dest, port);
                    System.Threading.Thread.Sleep(interval_char);
                }
                //ssid:
                int count_ssid = (ssid.Length + 1) / 2;
                for (int i = 0; i < count_ssid; i++)
                {
                    string a1 = "238";
                    string a2 = (80 + i).ToString();
                    string a3 = (Convert.ToChar(ssid.Substring(i * 2, 1)) + 0).ToString();
                    string a4 = (ssid.Length % 2 == 1 && i == count_ssid - 1) ? "128" : (Convert.ToChar(ssid.Substring(i * 2 + 1, 1)) + 128).ToString();
                    string dest = a1 + "." + a2 + "." + a3 + "." + a4;
                    client.Send(content, content.Length, dest, port);
                    System.Threading.Thread.Sleep(interval_char);
                }
                //pswd:
                int count_pswd = (pswd.Length + 1) / 2;
                for (int i = 0; i < count_pswd; i++)
                {
                    string a1 = "238";
                    string a2 = (80 + i).ToString();
                    string a3 = (Convert.ToChar(pswd.Substring(i * 2, 1)) + 128).ToString();
                    string a4 = (pswd.Length % 2 == 1 && i == count_pswd - 1) ? "0" : (Convert.ToChar(pswd.Substring(i * 2 + 1, 1)) + 0).ToString();
                    string dest = a1 + "." + a2 + "." + a3 + "." + a4;
                    client.Send(content, content.Length, dest, port);
                    System.Threading.Thread.Sleep(interval_char);
                }
                //langusge:
                {
                    string dest = "238.81.129.128";
                    client.Send(content, content.Length, dest, port);
                    System.Threading.Thread.Sleep(interval_char);
                }
                //interval:
                System.Threading.Thread.Sleep(interval);
            }

            client.Close();
        }
Example #38
0
        /// <summary>
        /// Stops listening for incoming connections
        /// </summary>
        public override void Stop()
        {
            if (!Running)
                return;
			System.Net.Sockets.UdpClient listener = this.listener;
			this.listener = null;
            listener.Close();
        }
Example #39
0
        /// <summary>
        /// UDP実行
        /// </summary>
        /// <param name="command">コマンド</param>
        /// <param name="no">カメラ番号</param>
        protected void runUdp(string command,string no)
        {
            //データを送信するリモートホストとポート番号
            string remoteHost = _json.remoteHost;
            int remotePort = (int)_json.remotePort;

            //UdpClientオブジェクトを作成する
            System.Net.Sockets.UdpClient udp = new System.Net.Sockets.UdpClient();

            //送信するデータを作成する
            string msg = "";
            msg = "command : " + command + "\r\n";
            msg += "camera_no : " + no + "\r\n";
            msg += "authenticate_code : \r\n";
            msg += "\r\n";
            byte[] sendBytes = Encoding.UTF8.GetBytes(msg);

            //リモートホストを指定してデータを送信する
            udp.Send(sendBytes, sendBytes.Length, remoteHost, remotePort);

            //UdpClientを閉じる
            udp.Close();
        }