private void connectButton_Click(object sender, EventArgs e) { if (connectButton.Text == "Connect") { // TODO: look at not disposing this everytime _tcpListener = new TCPListener(int.Parse(portTextBox.Text), ackCB.Checked, tcpListenerCallback); _tcpListener.LoggingCallback = tcpStatusCallback; _tcpListener.Start(); connectButton.Text = "Disconnect"; } else if (connectButton.Text == "Disconnect") { _tcpListener.Stop(); connectButton.Text = "Connect"; } }
public TcpConnection(Socket socket, TCPListener owner) { _socket = socket; _owner = owner; try { _socket.BeginReceive(_receiveBuffer, 0, _receiveBuffer.Length, SocketFlags.None, receiveCallback, null); } catch (ObjectDisposedException) { // ignore this exception because it only happens when we reset the plugin } catch (Exception ex) { Log("Socket beginreceive failed : " + ex); } }
static void Main(string[] args) { AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit); //byte[] bytes = _messageGenerator.GetMessage(); //string byteString = BitConverter.ToString(bytes); SpyMessage spyMessage = new SpyMessage(); Console.WriteLine("Size: " + Marshal.SizeOf(spyMessage)); if (IsSerial) { string[] ports = SerialPort.GetPortNames(); _serialStream = new SerialStream("COM16", 2400); _serialStream.DataReceived += new Action<byte[]>(callBack); _serialStream.Start(); } else { _tcpListener = new TCPListener(7118, false, callBack); _tcpListener.Start(); } Console.WriteLine("Listening..."); Console.ReadLine(); }