Ejemplo n.º 1
0
        public static void SetUDPConnection()
        {
            var IPendPoint     = new IPEndPoint(IPAddress.Any, ServerUdpPort);
            var socketListener = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            socketListener.Bind(IPendPoint);
            Console.WriteLine("UDP севрер готов!");

            EndPoint remotePoint = new IPEndPoint(IPAddress.Any, 0);

            byte[] data = new byte[MessageCapacity];
            while (true)
            {
                int     amount  = socketListener.ReceiveFrom(data, ref remotePoint);
                Message message = messageSerializer.Deserialize(data, amount);
                if (message.messageType == Message.MessageType.SearchRequest)
                {
                    Message messageResponse = new Message()
                    {
                        IPAdress   = CommonInfo.GetHostsIPAddress().ToString(), messageType = Message.MessageType.SearchResponce,
                        serverPort = ServerTcpPort
                    };
                    var        iPaddress      = IPAddress.Parse(message.IPAdress);
                    IPEndPoint remoteEndPoint = new IPEndPoint(iPaddress, message.clientPort);
                    socketListener.SendTo(messageSerializer.Serialize(messageResponse), remoteEndPoint);
                }
            }
        }
Ejemplo n.º 2
0
        public static void SetUDPConnection()
        {
            var IPendPoint     = new IPEndPoint(IPAddress.Any, SERVERUDPPORT);
            var socketListener = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            socketListener.Bind(IPendPoint);

            EndPoint remotePoint = new IPEndPoint(IPAddress.Any, 0);

            byte[] data = new byte[1024];
            while (true)
            {
                int     amount  = socketListener.ReceiveFrom(data, ref remotePoint);
                Message message = messageSerializer.Deserialize(data, amount);
                if (message.messageType == Message.MessageType[6])
                {
                    Message messageResponse = new Message()
                    {
                        IPAdress = CommonInfo.GetHostsIPAddress().ToString(), messageType = Message.MessageType[7], serverPort = SERVERTCPPORT
                    };
                    var        iPaddress      = IPAddress.Parse(message.IPAdress);
                    IPEndPoint remoteEndPoint = new IPEndPoint(iPaddress, message.clientPort);
                    socketListener.SendTo(messageSerializer.Serialize(messageResponse), remoteEndPoint);
                }
            }
        }
Ejemplo n.º 3
0
        public static void SetTCPConnection()
        {
            IPAddress IPaddress      = CommonInfo.GetHostsIPAddress();
            var       IPendPoint     = new IPEndPoint(IPaddress, SERVERTCPPORT);
            var       socketListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            socketListener.Bind(IPendPoint);
            socketListener.Listen(MAXNUMBEROFUSERS);
            while (true)
            {
                Socket listeningClientMessagesSocket     = socketListener.Accept();
                ClientConnectionManager clientConnection = new ClientConnectionManager(listeningClientMessagesSocket);
            }
        }
Ejemplo n.º 4
0
        public static void SetTCPConnection()
        {
            IPAddress IPaddress      = CommonInfo.GetHostsIPAddress();
            var       IPendPoint     = new IPEndPoint(IPaddress, ServerTcpPort);
            var       socketListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            socketListener.Bind(IPendPoint);
            socketListener.Listen(MaxNumberOfUsers);
            Console.WriteLine("TCP севрер готов!");
            while (true)
            {
                Socket listeningClientMessagesSocket     = socketListener.Accept();
                ClientConnectionManager clientConnection = new ClientConnectionManager(listeningClientMessagesSocket);
            }
        }
Ejemplo n.º 5
0
        public void SetClientSocketForUDPListening()
        {
            listeningUDPSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            IPAddress  IPaddress    = CommonInfo.GetHostsIPAddress();
            IPEndPoint IPLocalPoint = new IPEndPoint(IPaddress, SERVERUDPPORT);

            listeningUDPSocket.Bind(IPLocalPoint);

            var message = new Message(IPaddress.ToString(), SERVERUDPPORT, Message.MessageType[6]);

            IPAddress  broadcastIPaddress = CommonInfo.GetHostsBroadcastIPAddress();
            IPEndPoint IPendPoint         = new IPEndPoint(broadcastIPaddress, SERVERUDPPORT);

            listeningUDPSocket.SendTo(messageSerializer.Serialize(message), IPendPoint);

            Thread threadReceiveUDPMessages = new Thread(ReceiveUDPMessages);

            threadsList.Add(threadReceiveUDPMessages);
            threadReceiveUDPMessages.Start();
        }