public static void ListenTcp() { Socket socketListener; IPEndPoint endPoint = new IPEndPoint(StandartInfo.GetCurrentIP(), port); socketListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socketListener.Bind(endPoint); socketListener.Listen(MaxUsersAmount); Console.WriteLine("The server is avaible (TCP)"); while (true) { Socket socketClientHandler = socketListener.Accept(); ConnectionHandler connection = new ConnectionHandler(socketClientHandler); } }
public static void HandleSearchMessage(Message message) { Message messageResponse = new Message() { IPAdress = StandartInfo.GetCurrentIP(). ToString(), Port = port, messageType = MessageType.SearchResponse }; //Message messageResponse = new Message(StandartInfo.GetCurrentIP().ToString(), port, MessageType.SearchResponse); Socket socketSetAdress = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(message.IPAdress), message.Port); socketSetAdress.SendTo(messageSerializer.Serialize(messageResponse), endPoint); }
public void UdpBroadcastRequest() { Message message = new Message(); message.messageType = MessageType.SearchRequest; message.Port = ((IPEndPoint)socketUdpHandler.LocalEndPoint).Port; message.IPAdress = StandartInfo.GetCurrentIP().ToString(); IPEndPoint IPendPoint = new IPEndPoint(IPAddress.Parse(BroadcastIP), ServerPort); Socket sendRequest = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); sendRequest.SendTo(messageSerializer.Serialize(message), IPendPoint); Thread threadReceiveUdp = new Thread(ReceiveMessagesUdp); threads.Add(threadReceiveUdp); threadReceiveUdp.Start(); }