private static void writeSent(IAsyncResult ar)
        {
            try {
                // Retrieve the socket from the state object.
                SocketClientExample example = (SocketClientExample)ar.AsyncState;

                // Complete sending the data to the remote device.
                int bytesSent = example.currentConnection.EndSend(ar);
                Console.WriteLine("Sent {0} bytes to server.", bytesSent);

                // Signal that all bytes have been sent.
                example.sendWaiter.Set();
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
            }
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            Console.WriteLine("\nPress ENTER to continue...");
            Console.Read();

            IPHostEntry ipHostInfo = Dns.Resolve (Dns.GetHostName ());
            IPAddress ipAddress = ipHostInfo.AddressList[0];
            IPEndPoint remoteEP = new IPEndPoint(ipAddress,11000);
            try{
                listeners += new EventLoop(nextMessage);
                client = new SocketClientExample (remoteEP);
                client.connect();
                client.listeners += new MessageListener(recievedMessage);
                Console.WriteLine("Listener Length: {0}", listeners.GetInvocationList().Length.ToString());
                while (listeners.GetInvocationList().Length > 0){
                    listeners();
                }
                Console.WriteLine("Finished Exec");
            }catch(Exception e){
                Console.WriteLine (e.ToString());
            }
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            Console.WriteLine("\nPress ENTER to continue...");
            Console.Read();

            IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
            IPAddress   ipAddress  = ipHostInfo.AddressList[0];
            IPEndPoint  remoteEP   = new IPEndPoint(ipAddress, 11000);

            try{
                listeners += new EventLoop(nextMessage);
                client     = new SocketClientExample(remoteEP);
                client.connect();
                client.listeners += new MessageListener(recievedMessage);
                Console.WriteLine("Listener Length: {0}", listeners.GetInvocationList().Length.ToString());
                while (listeners.GetInvocationList().Length > 0)
                {
                    listeners();
                }
                Console.WriteLine("Finished Exec");
            }catch (Exception e) {
                Console.WriteLine(e.ToString());
            }
        }