Exemple #1
0
 private void cmdConnect_Click(object sender, System.EventArgs e)
 {
     _sender.IP   = txtIP.Text;
     _sender.Port = (int)numPort.Value;
     if (_sender.Connect())
     {
         lblConnected.Text      = "Connected";
         lblConnected.ForeColor = Color.Blue;
     }
     else
     {
         lblConnected.Text      = "Not Connected";
         lblConnected.ForeColor = Color.Red;
     }
 }
Exemple #2
0
        /// <summary>
        /// Shows the options for this application. The OptionsForm defines what
        /// options are available, and exports them in a public structure.
        /// </summary>
        /// <param name="sender">The sender of this event.</param>
        /// <param name="e">The arguments for this event.</param>
        private void mniTestOptions_Click(object sender, EventArgs e)
        {
            OptionsForm dlg = new OptionsForm(_o);

            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                // stop any sending or listening
                if (_sender != null && _sender.IsConnected)
                {
                    _sender.Disconnect();
                }
                if (_listener != null && _listener.IsListening)
                {
                    _listener.Stop();
                }

                // set our options reference
                _o = dlg.Settings;

                // potentially start receiving as a network server
                if (_o.ReceiveOnNet)
                {
                    if (_o.UseWebSockets)
                    {
                        _listener = new WebSocketListener(this); // ws
                    }
                    else
                    {
                        _listener = new NetListener(this); // tcp
                    }
                    _listener.NetDataEvent += new NetListener.NetEventHandler(OnNetworkDataReceived);

                    _listener.IP   = _o.ReceiveIP;
                    _listener.Port = _o.ReceivePort;
                    _listener.Start();
                }

                // potentially start sending as a network client
                if (_o.SendOnTcp)
                {
                    _sender      = new NetSender();
                    _sender.IP   = _o.SendIP;
                    _sender.Port = _o.SendPort;
                    _sender.Connect();
                }
            }
        }