looping it up and cleaning up whitespace, too
This commit is contained in:
parent
665d867bc4
commit
46def9b2f6
@ -8,18 +8,25 @@ namespace MarcoPoloClient
|
|||||||
{
|
{
|
||||||
class MainClass
|
class MainClass
|
||||||
{
|
{
|
||||||
const int MARCO_POLO_PORT = 22000;
|
const int MARCO_POLO_PORT = 22000;
|
||||||
const string MARCO_POLO_SERVER = "127.0.0.1";
|
const string MARCO_POLO_SERVER = "127.0.0.1";
|
||||||
|
|
||||||
public static void Main (string[] args)
|
public static void Main (string[] args)
|
||||||
{
|
{
|
||||||
SocketClient client = new SocketClient();
|
while (true)
|
||||||
string result = client.Connect(MARCO_POLO_SERVER, MARCO_POLO_PORT);
|
{
|
||||||
result = client.Send("polo doreen 25 75\n");
|
SocketClient client = new SocketClient();
|
||||||
Console.WriteLine(String.Format("'polo' got back: '{0}'", result));
|
|
||||||
string response = client.Receive();
|
string result = client.Connect(MARCO_POLO_SERVER, MARCO_POLO_PORT);
|
||||||
Console.WriteLine(String.Format("'polo' response: '{0}'", response));
|
result = client.Send("polo doreen 25 75\n");
|
||||||
client.Close();
|
Console.WriteLine(String.Format("'polo' got back: '{0}'", result));
|
||||||
|
string response = client.Receive();
|
||||||
|
Console.WriteLine(String.Format("'polo' response: '{0}'", response));
|
||||||
|
client.Close();
|
||||||
|
|
||||||
|
Console.WriteLine("sleeping for half a second...");
|
||||||
|
Thread.Sleep(500);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,10 +30,11 @@ namespace MarcoPoloClient
|
|||||||
socketEventArg.RemoteEndPoint = hostEntry;
|
socketEventArg.RemoteEndPoint = hostEntry;
|
||||||
|
|
||||||
socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs> (delegate(object s, SocketAsyncEventArgs e)
|
socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs> (delegate(object s, SocketAsyncEventArgs e)
|
||||||
{
|
{
|
||||||
result = e.SocketError.ToString ();
|
result = e.SocketError.ToString ();
|
||||||
_clientDone.Set ();
|
_clientDone.Set ();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
_clientDone.Reset ();
|
_clientDone.Reset ();
|
||||||
_socket.ConnectAsync (socketEventArg);
|
_socket.ConnectAsync (socketEventArg);
|
||||||
@ -52,10 +53,11 @@ namespace MarcoPoloClient
|
|||||||
socketEventArg.UserToken = null;
|
socketEventArg.UserToken = null;
|
||||||
|
|
||||||
socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs> (delegate(object s, SocketAsyncEventArgs e)
|
socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs> (delegate(object s, SocketAsyncEventArgs e)
|
||||||
{
|
{
|
||||||
response = e.SocketError.ToString ();
|
response = e.SocketError.ToString ();
|
||||||
_clientDone.Set ();
|
_clientDone.Set ();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
byte[] payload = Encoding.UTF8.GetBytes (data);
|
byte[] payload = Encoding.UTF8.GetBytes (data);
|
||||||
socketEventArg.SetBuffer (payload, 0, payload.Length);
|
socketEventArg.SetBuffer (payload, 0, payload.Length);
|
||||||
@ -79,15 +81,16 @@ namespace MarcoPoloClient
|
|||||||
|
|
||||||
socketEventArg.SetBuffer (new Byte[MAX_BUFFER_SIZE], 0, MAX_BUFFER_SIZE);
|
socketEventArg.SetBuffer (new Byte[MAX_BUFFER_SIZE], 0, MAX_BUFFER_SIZE);
|
||||||
socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs> (delegate(object s, SocketAsyncEventArgs e)
|
socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs> (delegate(object s, SocketAsyncEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.SocketError == SocketError.Success) {
|
if (e.SocketError == SocketError.Success) {
|
||||||
response = Encoding.UTF8.GetString (e.Buffer, e.Offset, e.BytesTransferred);
|
response = Encoding.UTF8.GetString (e.Buffer, e.Offset, e.BytesTransferred);
|
||||||
response = response.Trim ('\0');
|
response = response.Trim ('\0');
|
||||||
} else {
|
} else {
|
||||||
response = e.SocketError.ToString ();
|
response = e.SocketError.ToString ();
|
||||||
|
}
|
||||||
|
_clientDone.Set ();
|
||||||
}
|
}
|
||||||
_clientDone.Set ();
|
);
|
||||||
});
|
|
||||||
|
|
||||||
_clientDone.Reset ();
|
_clientDone.Reset ();
|
||||||
_socket.ReceiveAsync (socketEventArg);
|
_socket.ReceiveAsync (socketEventArg);
|
||||||
|
Loading…
Reference in New Issue
Block a user