who can tell me what's wrong with the code
-
the code is in the SDK,but wen i run it,nothing happened,except print "Connected xxx.xxx.xxx",it cann't receive message from the server,but the SDK say it can Receive Message From The Server,why?? The Address in SDK is:ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconnon-blockingclientsocketexample.htm using System; using System.Net; using System.Net.Sockets; using System.Threading; using System.Text; // State object for receiving data from remote device. public class StateObject { public Socket workSocket = null; // Client socket. public const int BufferSize = 256; // Size of receive buffer. public byte[] buffer = new byte[BufferSize]; // Receive buffer. public StringBuilder sb = new StringBuilder();// Received data string. } public class AsynchronousClient { // The port number for the remote device. private const int port = 21; // ManualResetEvent instances signal completion. private static ManualResetEvent connectDone = new ManualResetEvent(false); private static ManualResetEvent sendDone = new ManualResetEvent(false); private static ManualResetEvent receiveDone = new ManualResetEvent(false); // The response from the remote device. private static String response = String.Empty; private static void StartClient() { // Connect to a remote device. try { // Establish the remote endpoint for the socket. // "host.contoso.com" is the name of the // remote device. IPHostEntry ipHostInfo = Dns.Resolve(Ftp.xxxx.com); IPAddress ipAddress = ipHostInfo.AddressList[0]; IPEndPoint remoteEP = new IPEndPoint(ipAddress, port); // Create a TCP/IP socket. Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // Connect to the remote endpoint. client.BeginConnect( remoteEP, new AsyncCallback(ConnectCallback), client); connectDone.WaitOne(); // Send test data to the remote device. Send(client,"USER xxx\r\n"); sendDone.WaitOne(); // Receive the response from the remote device. Receive(client); receiveDone.WaitOne(); // Write the response to the console. Console.WriteLine("Response received : {0}", response); // Release the socket. client.Shutdown(SocketShutdown.Both); client.Close(); } catch (Exception e) { Console.WriteLine(e.ToString()); } } private static void ConnectCallback(IAsyncResult ar) { try { // Retrieve the socket from the state object. Socket client = (Socket) ar.AsyncState; // Complete the connection. client.EndConnect(ar); Console.WriteLine("Socket connected to {0}", client.RemoteEndPo
-
the code is in the SDK,but wen i run it,nothing happened,except print "Connected xxx.xxx.xxx",it cann't receive message from the server,but the SDK say it can Receive Message From The Server,why?? The Address in SDK is:ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconnon-blockingclientsocketexample.htm using System; using System.Net; using System.Net.Sockets; using System.Threading; using System.Text; // State object for receiving data from remote device. public class StateObject { public Socket workSocket = null; // Client socket. public const int BufferSize = 256; // Size of receive buffer. public byte[] buffer = new byte[BufferSize]; // Receive buffer. public StringBuilder sb = new StringBuilder();// Received data string. } public class AsynchronousClient { // The port number for the remote device. private const int port = 21; // ManualResetEvent instances signal completion. private static ManualResetEvent connectDone = new ManualResetEvent(false); private static ManualResetEvent sendDone = new ManualResetEvent(false); private static ManualResetEvent receiveDone = new ManualResetEvent(false); // The response from the remote device. private static String response = String.Empty; private static void StartClient() { // Connect to a remote device. try { // Establish the remote endpoint for the socket. // "host.contoso.com" is the name of the // remote device. IPHostEntry ipHostInfo = Dns.Resolve(Ftp.xxxx.com); IPAddress ipAddress = ipHostInfo.AddressList[0]; IPEndPoint remoteEP = new IPEndPoint(ipAddress, port); // Create a TCP/IP socket. Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // Connect to the remote endpoint. client.BeginConnect( remoteEP, new AsyncCallback(ConnectCallback), client); connectDone.WaitOne(); // Send test data to the remote device. Send(client,"USER xxx\r\n"); sendDone.WaitOne(); // Receive the response from the remote device. Receive(client); receiveDone.WaitOne(); // Write the response to the console. Console.WriteLine("Response received : {0}", response); // Release the socket. client.Shutdown(SocketShutdown.Both); client.Close(); } catch (Exception e) { Console.WriteLine(e.ToString()); } } private static void ConnectCallback(IAsyncResult ar) { try { // Retrieve the socket from the state object. Socket client = (Socket) ar.AsyncState; // Complete the connection. client.EndConnect(ar); Console.WriteLine("Socket connected to {0}", client.RemoteEndPo
Are any exceptions being thrown? James Sonork ID: 100.11138 - Hasaki "Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. :-D" - Michael P Butler Jan. 18, 2002