コード例 #1
0
        private static void clientmode()
        {
            Console.WriteLine();
            NetworkClient nc = new NetworkClient(SERVER_IP, PORT);

            if (nc.Connect() == false)
            {
                Console.WriteLine("Server not available");
                return;
            }
            string DataToSend = "";

            while (DataToSend != "quit")
            {
                Console.WriteLine("\nType a text to be sent:");
                StringBuilder sb = new StringBuilder();

                DataToSend = Console.ReadLine();

                if (DataToSend.Length == 0)
                {
                    continue;
                }
                Packet packet = new Packet();
                packet.Message = DataToSend;
                try
                {
                    nc.Connect();
                    ReturnPacket ret = nc.Send(packet) as ReturnPacket;
                    if (ret != null)
                    {
                        string returndata = ret.Message;
                        Console.WriteLine("This is what the host returned to you: \r\n{0}", returndata);
                    }
                    else
                    {
                        Console.WriteLine("return null");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    return;
                }
            }
            nc.Close();
        }
コード例 #2
0
        private static object HandlePacket(Packet dp)
        {
            ReturnPacket ret = new ReturnPacket();

            if (dp.SessionGuid == Guid.Empty)
            {
                // Authenticate username and password possibly with LDAP server
            }
            else
            {
                // check sessionguid valid -> if not return failed
            }
            ret.OK      = true;
            ret.Message = "your msg : " + dp.Message + "\r\nreturn from server " + DateTime.Now;
            count++;
            if (DateTime.Now.Subtract(dt).TotalMilliseconds > 10000)
            {
                Console.WriteLine("count in 10 secs = " + count);
                count = 0;
                dt    = DateTime.Now;
            }
            return(ret);
        }