Пример #1
0
 public static string Serialize(JMessage message)
 {
     return(JToken.FromObject(message).ToString());
 }
Пример #2
0
        private void callThread()
        {
            writer = new BinaryWriter(connection.GetStream());
            reader = new BinaryReader(connection.GetStream());

            while (true)
            {
                try
                {
                    string   received_data   = reader.ReadString();
                    JMessage received_object = JMessage.Deserialize(received_data);
                    if (received_object.Type == typeof(ControlPacket))
                    {
                        ControlPacket packet = received_object.Value.ToObject <ControlPacket>();
                        if (packet.virtualInterface == ControlInterface.CALL_ACCEPT)
                        {
                            if (packet.state == ControlPacket.ACCEPT)
                            {
                                clientWindowHandler.addToConnectionCombobox(packet.RequestID, packet.destinationIdentifier);
                                clientWindowHandler.slots.Clear();
                                if (packet.Vc11 != 0)
                                {
                                    clientWindowHandler.slots.Add(11);
                                }
                                if (packet.Vc12 != 0)
                                {
                                    clientWindowHandler.slots.Add(12);
                                }
                                if (packet.Vc13 != 0)
                                {
                                    clientWindowHandler.slots.Add(13);
                                }

                                clientWindowHandler.Log2("CONTROL", "CPCC <- NCC Call Request Accepted");
                            }
                            else
                            {
                                clientWindowHandler.Log2("CONTROL", "CPCC <- NCC Call Request Rejected");
                            }
                        }
                        else if (packet.virtualInterface == ControlInterface.INIT_CPCC_CONNECTION_CONFIRM)
                        {
                            clientWindowHandler.Log2("CONTROL", "CPCC <-> NCC connection established");
                        }
                        else if (packet.virtualInterface == ControlInterface.CALL_INDICATION_CPCC)
                        {
                            clientWindowHandler.Log2("CPCC <- NCC", "Receive Call Indication");
                            ControlPacket packetToNCC = new ControlPacket(ControlInterface.CALL_INDICATION_CPCC_ACCEPT, packet.state, packet.speed, packet.destinationIdentifier, packet.originIdentifier, packet.RequestID);
                            packetToNCC.Vc11 = packet.Vc11;
                            packetToNCC.Vc12 = packet.Vc12;
                            packetToNCC.Vc13 = packet.Vc13;
                            string data = JMessage.Serialize(JMessage.FromValue(packetToNCC));
                            writer.Write(data);
                            clientWindowHandler.Log2("CPCC -> NCC", "Send Call Indication Confirmation");
                        }
                    }
                    else
                    {
                        clientWindowHandler.Log2("CONTROL", "Wrong control packet format");
                    }
                }
                catch (IOException e)
                {
                    clientWindowHandler.Log2("CONTROL", "CPCC <-> NCC Connection closed");
                    break;
                }
            }
        }
Пример #3
0
        private void ListenThread(Object client)
        {
            TcpClient    clienttmp = (TcpClient)client;
            BinaryReader reader    = new BinaryReader(clienttmp.GetStream());

            writer = new BinaryWriter(clienttmp.GetStream());
            while (true)
            {
                string   received_data   = reader.ReadString();
                JMessage received_object = JMessage.Deserialize(received_data);
                if (received_object.Type == typeof(Signal))
                {
                    Signal received_signal = received_object.Value.ToObject <Signal>();
                    if (received_signal.stm1 != null)
                    {
                        STM1 received_frame = received_signal.stm1;
                        if (received_frame.vc4.vc3List.Count > 0)
                        {
                            slots.Clear();
                            foreach (KeyValuePair <int, VirtualContainer3> v in received_frame.vc4.vc3List)
                            {
                                receivedTextBox.AppendText(DateTime.Now.ToLongTimeString() + " : " + v.Value.C3);
                                receivedTextBox.AppendText(Environment.NewLine);
                                Log1("IN", virtualIP, received_signal.port.ToString(), v.Key, "VC-3", v.Value.POH.ToString(), v.Value.C3);
                                slots.Add(v.Key);
                            }
                        }
                        else
                        {
                            receivedTextBox.AppendText(DateTime.Now.ToLongTimeString() + " : " + received_frame.vc4.C4);
                            receivedTextBox.AppendText(Environment.NewLine);
                            Log1("IN", virtualIP, received_signal.port.ToString(), 1, "VC-4", received_frame.vc4.POH.ToString(), received_frame.vc4.C4);
                        }

                        logTextBox.AppendText(Environment.NewLine);
                        logTextBox.Paste("Path: \n");
                        foreach (var log in received_signal.path)
                        {
                            logTextBox.Paste(log + " -> ");
                        }
                        logTextBox.Paste(this.virtualIP);
                    }
                    else if (received_signal.lrmProtocol != null)
                    {
                        string   lrmProtocol = received_signal.lrmProtocol;
                        int      port        = received_signal.port;
                        string[] temp        = lrmProtocol.Split(' ');
                        if (temp[0] == "whoyouare")
                        {
                            string message = "iam " + this.virtualIP;
                            Signal signal  = new Signal(port, message);
                            string data    = JMessage.Serialize(JMessage.FromValue(signal));
                            writer.Write(data);
                        }
                    }
                }
                else
                {
                    Log2("ERR", "Received unknown data type from client");
                }
            }

            // reader.Close();
        }