Exemple #1
0
            //public void Start(string UserIP)
            //{
            //    client = new TcpClient(UserIP, 5000);

            //    Thread listenerThread = new Thread(Send);
            //    listenerThread.Start();

            //    Thread senderThread = new Thread(Listen);
            //    senderThread.Start();

            //    senderThread.Join();
            //    listenerThread.Join();
            //}
            #endregion



            //public void Start()

            //{
            //    BatProtocol testProtocol = new BatProtocol { Type = "Login", UserName = "******", Password = "******", RecieverIP = "10.20.38.150", RecieverPort = 5000 };
            //    client = new TcpClient(testProtocol.RecieverIP, testProtocol.RecieverPort);

            //    Thread batThread = new Thread(SendProtocol);
            //    batThread.Start(testProtocol);

            //    Thread listenerThread = new Thread(Send);
            //    listenerThread.Start();

            //    Thread senderThread = new Thread(Listen);
            //    senderThread.Start();

            //    senderThread.Join();
            //    listenerThread.Join();
            //    batThread.Join();
            //}

            public void Listen()
            {
                string message = "In case of no inputstring: This is the response";

                try
                {
                    while (true)
                    {
                        //Här kommer svarsobjektet
                        NetworkStream n = client.GetStream();
                        message = new BinaryReader(n).ReadString();
                        //dekoda message till objekt
                        BatProtocol deSerializedMessage = JsonConvert.DeserializeObject <BatProtocol>(message);
                        //Console.WriteLine("MessageType: " + deSerializedMessage.Type);

                        this.messType = deSerializedMessage.Type;

                        if (deSerializedMessage.Type == "Ok")
                        {
                            messType = "We're thoroughugh";
                        }
                        else if (deSerializedMessage.Type == "SM")
                        {
                            messType = deSerializedMessage.Message;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
Exemple #2
0
            public void SendProtocol(Object input)
            {
                BatProtocol p = (BatProtocol)input;
                //client = new TcpClient(p.RecieverIP, p.RecieverPort);

                NetworkStream n = client.GetStream();
                BinaryWriter  w = new BinaryWriter(n);

                string protocol = JsonConvert.SerializeObject(input);

                w.Write(protocol);
            }