Esempio n. 1
0
        //czy tu powinno byc cos wiecej? chyba jakas lambda czy cos powinna byc w logach
        private void ProcessPacket(StateObject state, Socket handler, IAsyncResult ar)
        {
            try
            {
                MyPacket receivedpacket = MyPacket.BytesToPacket(state.Buffer);

                string myNodeName = SocketToNodeName[handler];
                string myNodeIP   = NodeAddressDictionary[myNodeName];
                int    actualPort = HackishPortTranslation(receivedpacket.Port, myNodeName);
                string myNodePort = Convert.ToString(actualPort);


                //dopisuję, wypisze czestotliwosc
                string myFreq = Convert.ToString(receivedpacket.Frequency);
                NewLog($"Received packet from {myNodeIP} port {myNodePort}", myWindow, "LightCyan");

                foreach (KeyValuePair <string, string> entry in NodeAddressDictionary)
                {
                    // NewLog($"iauhsduh vuhv  {entry.Value} ", myWindow, "Green");
                }

                string myNodeNext = NextCableNode(myNodeName, myNodePort);

                string myPortNext = NextCablePort(myNodeName, myNodePort);

                string myIPNext = NodeAddressDictionary[myNodeNext];



                receivedpacket.Port = int.Parse(myPortNext);
                Socket tmpsocket = NodeNameToSocket[myNodeNext];
                SendPacket(tmpsocket, receivedpacket.PacketToBytes());
                NewLog($"Send packet to {myIPNext} port {myPortNext}", myWindow, "LightCyan");
            }
            catch (Exception ex)
            {
                NewLog($"Connection failed {ex}", myWindow, "LightCyan");
            }
        }