Wanted to test the UDPClient class out while I was at school. I am connected to the school's wireless which has a strict firewall.
This code seems pretty solid when compared to this example. (http://msdn.microsoft.com/en-us/library/system.net.sockets.udpclient.aspx) But when I open up wireshark I don't see any of my packets (when I am filtering for UDP packets or otherwise).
Any ideas on what could be wrong with my code? I am thinking it's being blocked by the school's firewall but I'm not sure.
public static void CallBack(IAsyncResult result)
{
UdpClient myClient = result.AsyncState as UdpClient;
int sent = myClient.EndSend(result);
Console.WriteLine("Sent " + sent.ToString() + " bytes");
}
static void Main(string[] args)
{
UdpClient myClient = new UdpClient(57422);
try
{
myClient.Connect(IPAddress.Parse("127.0.0.1"), 57422);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
int b = 1;
b = IPAddress.HostToNetworkOrder(b);
string myName = "ALEX";
int lengthOfB = System.BitConverter.GetBytes(b).Length;
int lengthOfName = NUEncoder.GetByteCount(myName);
Byte[] intBytes = System.BitConverter.GetBytes(b);
Byte[] nameBytes = NUEncoder.GetBytes(myName);
Byte[] bytesToSend = new Byte[lengthOfB + lengthOfName];
int i = 0;
for (i = 0; i < lengthOfName; i++)
{
bytesToSend[i] = nameBytes[i];
}
for (int k = 0; k < lengthOfB; k++)
{
bytesToSend[i] = intBytes[k];
i++;
}
myClient.BeginSend(bytesToSend, bytesToSend.Length, CallBack, myClient);
Console.WriteLine("Sleeping...");
Thread.Sleep(50);
Console.WriteLine("Done");
}
}