コード例 #1
0
ファイル: MainClientForm.cs プロジェクト: shockwavemk/pace
 private void ConfigServerOnChanged(object sender, ChangedEventArgs eventArgs)
 {
     ConnectToServer(eventArgs.Ip, eventArgs.Port);
 }
コード例 #2
0
ファイル: MainClientForm.cs プロジェクト: danorama/pace
 private void ConfigServerOnChanged(object sender, ChangedEventArgs eventArgs)
 {
     ConnectToServer(eventArgs.Ip, eventArgs.Port);
 }
コード例 #3
0
ファイル: ConfigServer.cs プロジェクト: shockwavemk/pace
 protected virtual void OnChanged(ChangedEventArgs e)
 {
     if (Changed != null)
         Changed(this, e);
 }
コード例 #4
0
ファイル: ConfigServer.cs プロジェクト: shockwavemk/pace
        private void ConfigTasks()
        {
            try
            {
                Byte[] data;
                String responseData = String.Empty;
                var server = new TcpListener(IPAddress.Any, _port);
                server.Start();

                while (_running)
                {
                    Thread.Sleep(Threshold);
                    while (!server.Pending()) { Thread.Sleep(Threshold); }

                    TcpClient client = server.AcceptTcpClient();
                    NetworkStream stream = client.GetStream();

                    IPEndPoint remoteIpEndPoint = client.Client.RemoteEndPoint as IPEndPoint;
                    IPEndPoint localIpEndPoint = client.Client.LocalEndPoint as IPEndPoint;

                    if (remoteIpEndPoint != null) { TraceOps.Out(remoteIpEndPoint.Address + " : " + remoteIpEndPoint.Port); }
                    if (localIpEndPoint != null)
                    {
                        TraceOps.Out(localIpEndPoint.Address + " : " + localIpEndPoint.Port);
                    }

                    while (client.Connected)
                    {
                        Thread.Sleep(Threshold);
                        data = new Byte[1024];
                        var connectIp = "";
                        var connectPort = 0;

                        Int32 bytes = stream.Read(data, 0, data.Length);
                        responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
                        if (responseData != "")
                        {

                            if (responseData.IndexOf("<PORT>", StringComparison.Ordinal) > 0)
                            {
                                connectPort = Convert.ToInt32(NetworkOps.GetValue("PORT", responseData));
                                TraceOps.Out("Recived PORT: " + connectPort);
                            }
                            if (responseData.IndexOf("<IP>", StringComparison.Ordinal) > 0)
                            {
                                connectIp = NetworkOps.GetValue("IP", responseData);
                                connectIp = NetworkOps.GetIpString(connectIp);
                                TraceOps.Out("Recived IP: " + connectIp);
                            }

                            if (responseData.IndexOf("</XML>", StringComparison.Ordinal) > 0)
                            {
                                stream.Close();
                                client.Close();

                                if (connectIp != "" && connectPort != 0 && remoteIpEndPoint != null)
                                {
                                    var e = new ChangedEventArgs(remoteIpEndPoint.Address.ToString(), connectPort);
                                    OnChanged(e);
                                }
                                TraceOps.Out("Recived End");
                            }
                        }
                    }

                    TraceOps.Out("Close Stream and TCP Connection");

                    if (client.Connected)
                    {
                        stream.Close();
                        client.Close();
                    }
                }
                server.Stop();
            }
            catch (Exception exception)
            {
                TraceOps.Out(exception.ToString());
            }
        }
コード例 #5
0
        private void ConfigTasks()
        {
            try
            {
                Byte[] data;
                String responseData = String.Empty;
                var    server       = new TcpListener(IPAddress.Any, _port);
                server.Start();

                while (_running)
                {
                    Thread.Sleep(Threshold);
                    while (!server.Pending())
                    {
                        Thread.Sleep(Threshold);
                    }

                    TcpClient     client = server.AcceptTcpClient();
                    NetworkStream stream = client.GetStream();

                    IPEndPoint remoteIpEndPoint = client.Client.RemoteEndPoint as IPEndPoint;
                    IPEndPoint localIpEndPoint  = client.Client.LocalEndPoint as IPEndPoint;

                    if (remoteIpEndPoint != null)
                    {
                        TraceOps.Out(remoteIpEndPoint.Address + " : " + remoteIpEndPoint.Port);
                    }
                    if (localIpEndPoint != null)
                    {
                        TraceOps.Out(localIpEndPoint.Address + " : " + localIpEndPoint.Port);
                    }


                    while (client.Connected)
                    {
                        Thread.Sleep(Threshold);
                        data = new Byte[1024];
                        var connectIp   = "";
                        var connectPort = 0;

                        Int32 bytes = stream.Read(data, 0, data.Length);
                        responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
                        if (responseData != "")
                        {
                            if (responseData.IndexOf("<PORT>", StringComparison.Ordinal) > 0)
                            {
                                connectPort = Convert.ToInt32(NetworkOps.GetValue("PORT", responseData));
                                TraceOps.Out("Recived PORT: " + connectPort);
                            }
                            if (responseData.IndexOf("<IP>", StringComparison.Ordinal) > 0)
                            {
                                connectIp = NetworkOps.GetValue("IP", responseData);
                                connectIp = NetworkOps.GetIpString(connectIp);
                                TraceOps.Out("Recived IP: " + connectIp);
                            }

                            if (responseData.IndexOf("</XML>", StringComparison.Ordinal) > 0)
                            {
                                stream.Close();
                                client.Close();

                                if (connectIp != "" && connectPort != 0 && remoteIpEndPoint != null)
                                {
                                    var e = new ChangedEventArgs(remoteIpEndPoint.Address.ToString(), connectPort);
                                    OnChanged(e);
                                }
                                TraceOps.Out("Recived End");
                            }
                        }
                    }

                    TraceOps.Out("Close Stream and TCP Connection");

                    if (client.Connected)
                    {
                        stream.Close();
                        client.Close();
                    }
                }
                server.Stop();
            }
            catch (Exception exception)
            {
                TraceOps.Out(exception.ToString());
            }
        }