public MCPConnector(IPAddress multicastAddress, int port, int ttl, IPAddress myIpAddress, int myPort, int maintainDelay) { //create connection for listener IPEndPoint whom = new IPEndPoint(multicastAddress, port);//default, becase listener will't send IPEndPoint wherefrom = whom; IPEndPoint bindEP = new IPEndPoint(IPAddress.Any, port); connection = new MulticastUdpConnection(whom, wherefrom, bindEP, ttl); //create listener listener = new Listener(); listener.Init(connection); listener.MessageAvailableEvent += NewMessageTask; this.myIpAddress = myIpAddress; this.myPort = myPort; this.maintainDelay = maintainDelay; pocketNumber = 0; maintainPacket = new MCPPacket(pocketNumber, myIpAddress, myPort, MCPState.Reset); Send(maintainPacket.GetPacketBytes()); pocketNumber += 1; maintainPacket = new MCPPacket(pocketNumber, myIpAddress, myPort, MCPState.MaintainConnection); maintainThread = new Thread(MaintainConnection); maintainThread.Start(); }
//Matches delegate type in connection class private void cbDisconnect(string inMessage) { ListenSocket = null; ConnectionSocket = null; //We disconnected from the client. Start listening again. StartListen(); }
private void cbConnectComplete(IAsyncResult asyncResult) { Socket temp = (Socket)asyncResult.AsyncState; try { temp.EndConnect(asyncResult); //Create our connection Connection = new Connection.Connection(temp, cbDataReceived, cbDisconnect); try { //Tell the user the connection succeeded Invoke(new Action(() => UI_label_Status.Text = "Connection succeeded")); } catch {} } catch (Exception ex) { Console.WriteLine(ex.Message); try { //Tell the user that the connection failed Invoke(new Action(() => UI_label_Status.Text = "Connection failed")); //Select a new port Invoke(new delVoidVoid(ClientConnectSelect)); } catch { } } }
//cbAccepts and cbErrors private void cbHandleAccept(Socket sok) { ConnectionSocket = new Connection.Connection(sok, cbDataReceived, cbDisconnect); ListenSocket.Close(); ListenSocket = null; try { Invoke(new Action(() => Text = "Server : Connected")); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public AudioListener(IPAddress ipAddress, int port) { this.IPAddress = ipAddress; this.Port = port; codec = new G722ChatCodec(); IPEndPoint defaultEP = new IPEndPoint(IPAddress.Any, 0); IPEndPoint wherefrom = new IPEndPoint(ipAddress, port); IPEndPoint bindEP = new IPEndPoint(IPAddress.Any, port); connection = new MulticastUdpConnection(defaultEP, wherefrom, bindEP, 100); listener = new Listener(); listener.Init(connection); listener.MessageAvailableEvent += DataAvailable; }
public Blockchain(Connection.Connection connection) { Connection = connection; Connection.NewMessage += new EventHandler <NewMessageEventArgs>(HandleNewMessage); }