J
Joshua Moore
Please help. I included the source code below. All I get from the buffer
is 0000000000000000. The exception it catches is "Message:
InvalidOperationException".
Thanks in advance,
Joshua Moore
public byte[] GetPacket()
{
byte[] buffer = new byte[82];
try
{
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);
EndPoint sender = new IPEndPoint(IPAddress.Any,2068);
socket.Blocking = false;
socket.Bind(sender);
int test = socket.ReceiveFrom(buffer, ref sender);
Console.WriteLine(test.ToString());
if (buffer[0] == 1)
{
Console.WriteLine("IT WORKS!");
socket.ReceiveFrom(buffer, ref sender);
}
}
catch(SocketException e)
{
Console.WriteLine("SocketException caught!!!");
Console.WriteLine("Message : " + e.Message);
}
catch(ArgumentNullException e)
{
Console.WriteLine("ArgumentNullException caught!!!");
Console.WriteLine("Message : " + e.Message);
}
catch(NullReferenceException e)
{
Console.WriteLine("NullReferenceException caught!!!");
Console.WriteLine("Message : " + e.Message);
}
catch(Exception e)
{
Console.WriteLine("Exception caught!!!");
Console.WriteLine("Message : " + e.Message);
}
return buffer;
}
public Network()
{
}
is 0000000000000000. The exception it catches is "Message:
InvalidOperationException".
Thanks in advance,
Joshua Moore
public byte[] GetPacket()
{
byte[] buffer = new byte[82];
try
{
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);
EndPoint sender = new IPEndPoint(IPAddress.Any,2068);
socket.Blocking = false;
socket.Bind(sender);
int test = socket.ReceiveFrom(buffer, ref sender);
Console.WriteLine(test.ToString());
if (buffer[0] == 1)
{
Console.WriteLine("IT WORKS!");
socket.ReceiveFrom(buffer, ref sender);
}
}
catch(SocketException e)
{
Console.WriteLine("SocketException caught!!!");
Console.WriteLine("Message : " + e.Message);
}
catch(ArgumentNullException e)
{
Console.WriteLine("ArgumentNullException caught!!!");
Console.WriteLine("Message : " + e.Message);
}
catch(NullReferenceException e)
{
Console.WriteLine("NullReferenceException caught!!!");
Console.WriteLine("Message : " + e.Message);
}
catch(Exception e)
{
Console.WriteLine("Exception caught!!!");
Console.WriteLine("Message : " + e.Message);
}
return buffer;
}
public Network()
{
}