Пример #1
0
        private ConsoleClient(string hostname, int port)
        {
            theConnection = new ClientConnection(hostname, port);

            Console.WriteLine("Sending connect request");

            ConnectResponse connResponse = theConnection.Connect();

            if (connResponse.success)
            {
                connected  = true;
                id         = connResponse.id;
                marketInfo = connResponse.marketInfo;
                Console.WriteLine("Connected successfully.");
            }
            else
            {
                Console.WriteLine("Connection unsuccessful.");
                Console.WriteLine("Aborting");
                throw new Exception();
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            ClientConnection clientConnection = new ClientConnection();


            clientConnection.Connect();
            clientConnection.SetUp();
            clientConnection.DoChat();

            //        byte[] receiveMessage = new byte[256];
            //        string data = null;
            //    }



            //            int bytesRead;

            //            while (true)
            //            {
            //                Console.Write("Entry: ");

            //                string sendMessage = Console.ReadLine();
            //                NetworkStream stream = client.GetStream();

            //                byte[] bytes = Encoding.ASCII.GetBytes(sendMessage);
            //                Console.WriteLine("Transmitting...");

            //                stream.Write(bytes, 0, bytes.Length);


            //                Console.WriteLine("Sent: {0}", sendMessage);


            //                    //try
            //                    //{
            //                        bytesRead = stream.Read(receiveMessage, 0, receiveMessage.Length);
            //                    //}
            //                    //catch
            //                    //{
            //                    //    break;
            //                    //}
            //                    //if (bytesRead == 0)
            //                    //{
            //                    //break;
            //                    //}
            //                    data = Encoding.ASCII.GetString(receiveMessage, 0, bytesRead);
            //                    Console.WriteLine("Received: {0}", data);
            //            }
            //            client.Close();
            //        }
            //        catch (Exception exception)
            //        {
            //            Console.WriteLine("Error...." + exception.StackTrace);
            //        }
            //        Console.ReadLine();
            //    }

            //    //public void CheckEndLoop()

            //    // {

            //    // }
            //}
        }