looping it up and cleaning up whitespace, too

This commit is contained in:
Dan Buch 2012-06-17 23:40:40 -04:00
parent 665d867bc4
commit 46def9b2f6
2 changed files with 47 additions and 37 deletions

View File

@ -8,18 +8,25 @@ namespace MarcoPoloClient
{
class MainClass
{
const int MARCO_POLO_PORT = 22000;
const string MARCO_POLO_SERVER = "127.0.0.1";
const int MARCO_POLO_PORT = 22000;
const string MARCO_POLO_SERVER = "127.0.0.1";
public static void Main (string[] args)
{
SocketClient client = new SocketClient();
string result = client.Connect(MARCO_POLO_SERVER, MARCO_POLO_PORT);
result = client.Send("polo doreen 25 75\n");
Console.WriteLine(String.Format("'polo' got back: '{0}'", result));
string response = client.Receive();
Console.WriteLine(String.Format("'polo' response: '{0}'", response));
client.Close();
while (true)
{
SocketClient client = new SocketClient();
string result = client.Connect(MARCO_POLO_SERVER, MARCO_POLO_PORT);
result = client.Send("polo doreen 25 75\n");
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);
}
}
}
}

View File

@ -30,10 +30,11 @@ namespace MarcoPoloClient
socketEventArg.RemoteEndPoint = hostEntry;
socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs> (delegate(object s, SocketAsyncEventArgs e)
{
result = e.SocketError.ToString ();
_clientDone.Set ();
});
{
result = e.SocketError.ToString ();
_clientDone.Set ();
}
);
_clientDone.Reset ();
_socket.ConnectAsync (socketEventArg);
@ -52,10 +53,11 @@ namespace MarcoPoloClient
socketEventArg.UserToken = null;
socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs> (delegate(object s, SocketAsyncEventArgs e)
{
response = e.SocketError.ToString ();
_clientDone.Set ();
});
{
response = e.SocketError.ToString ();
_clientDone.Set ();
}
);
byte[] payload = Encoding.UTF8.GetBytes (data);
socketEventArg.SetBuffer (payload, 0, payload.Length);
@ -79,15 +81,16 @@ namespace MarcoPoloClient
socketEventArg.SetBuffer (new Byte[MAX_BUFFER_SIZE], 0, MAX_BUFFER_SIZE);
socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs> (delegate(object s, SocketAsyncEventArgs e)
{
if (e.SocketError == SocketError.Success) {
response = Encoding.UTF8.GetString (e.Buffer, e.Offset, e.BytesTransferred);
response = response.Trim ('\0');
} else {
response = e.SocketError.ToString ();
{
if (e.SocketError == SocketError.Success) {
response = Encoding.UTF8.GetString (e.Buffer, e.Offset, e.BytesTransferred);
response = response.Trim ('\0');
} else {
response = e.SocketError.ToString ();
}
_clientDone.Set ();
}
_clientDone.Set ();
});
);
_clientDone.Reset ();
_socket.ReceiveAsync (socketEventArg);