public void RunReciever()
{
ListenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
try
{
// Setup the Socket
ListenSocket.Bind(new IPEndPoint(IPAddress.Parse(p_HostIP), 0));
ListenSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, 1);
ListenSocket.IOControl(unchecked((int) 0x98000001), new byte[4] {1, 0, 0, 0}, new byte[4]);
while (true) //Infinite Loop keeps the Socket in Listen
{
ListenSocket.BeginReceive(p_PacketBuffer, 0, p_PacketBufferSize, SocketFlags.None,
new AsyncCallback(CallReceive), this);
while (ListenSocket.Available == 0) // If no Data Sleep the thread for 1ms then check to see if there is data to be read
{
Thread.Sleep(1);
}
}
}
catch (ThreadAbortException){}// Catch the ThreadAbort Exception that gets generated whenever a thread is closed with the Thread.Abort() method
catch (Exception e) {new ErrorHandle(e);}
finally //Shutdown the Socket when finished
{
if (ListenSocket != null)
{
ListenSocket.Shutdown(SocketShutdown.Both);
ListenSocket.Close();
}
}
}