コード例 #1
0
        private void Disconnect()
        {
            picConnection1.BackColor = Color.Red;
            picConnection2.BackColor = Color.Red;

            if (myTCP_send != null)
            {
                myTCP_send.Dispose();
                myTCP_send = null;
            }

            if (myTCP_rec != null)
            {
                myTCP_rec.Dispose();
                myTCP_rec = null;
            }
        }
コード例 #2
0
        private void cmdConnect_Click(object sender, RoutedEventArgs e)
        {
            if (tcpFunc != null)
            {
                tcpFunc.AutoReConnect = false;
                tcpFunc.Dispose();
                tcpFunc = null;
                cmdConnect.Background = null;
            }
            else
            {
                IPAddress ip;

                if (!Properties.Settings.Default.Active)
                {
                    ip = IPAddress.Any;
                }
                else
                {
                    if (!IPAddress.TryParse(Properties.Settings.Default.IP, out ip))
                    {
                        IPAddress[] addresslist = Dns.GetHostAddresses(Properties.Settings.Default.IP);
                        foreach (var ipAddress in addresslist)
                        {
                            if (ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                            {
                                ip = ipAddress;
                                break;
                            }
                        }
                    }
                }

                try
                {
                    if (Properties.Settings.Default.RecieveFixedLength > 0)
                    {
                        tcpFunc = new TCPFunctionsAsync(SynchronizationContext.Current, ip, Int32.Parse(Properties.Settings.Default.Port), Properties.Settings.Default.Active, Properties.Settings.Default.RecieveFixedLength);
                    }
                    else
                    {
                        tcpFunc = new TCPFunctionsAsync(SynchronizationContext.Current, ip, Int32.Parse(Properties.Settings.Default.Port), Properties.Settings.Default.Active);
                    }

                    tcpFunc.DataRecieved          += tcpFunc_DataRecieved;
                    tcpFunc.ConnectionEstablished += tcpFunc_ConnectionEstablished;
                    tcpFunc.ConnectionClosed      += tcpFunc_ConnectionClosed;
                    tcpFunc.AutoReConnect          = true;
                    cmdConnect.Background          = Brushes.Orange;
                    tcpFunc.Start();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Fehler Creating Connection:" + ex.Message);
                }
            }
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: pwndubey77/s7-diff-merge
 private void cmdConnect_Click(object sender, EventArgs e)
 {
     if (tcpFunc != null)
     {
         tcpFunc.AutoReConnect = false;
         tcpFunc.Dispose();
         tcpFunc = null;
         cmdConnect.BackColor = Color.FromArgb(224, 224, 224);
     }
     else
     {
         tcpFunc = new TCPFunctionsAsync(SynchronizationContext.Current, IPAddress.Parse(txtIP.Text), Int32.Parse(txtPort.Text), chkActive.Checked);
         tcpFunc.DataRecieved          += tcpFunc_DataRecieved;
         tcpFunc.ConnectionEstablished += tcpFunc_ConnectionEstablished;
         tcpFunc.ConnectionClosed      += tcpFunc_ConnectionClosed;
         tcpFunc.AutoReConnect          = true;
         cmdConnect.BackColor           = Color.Orange;
         tcpFunc.Start();
     }
 }