Dear all,
I am working on receiving data from a DHCP server (linux machine) from a C# client program on windows. The server is connected to a hardware which sends out data on commands. It seems that I am able to send commands to the server and manage to get the hardware in capture mode but I cant receive any data. The progam just keeps polling.
This is the code:
class SimpleUdpClient
{
static byte[] msg = new byte[2000];
static IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9050);
static Socket fd = new Socket(AddressFamily.InterNetwork,SocketType.Dgram, ProtocolType.Udp);
static IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
static EndPoint Remote = (EndPoint)(sender);
static void send_msg()
{
if (fd == null)
{
Console.WriteLine("Failure to connect socket!");
}
fd.SendTo(msg,len, SocketFlags.None, ipep);
}
static void recieve_msg()
{ fd.Connect(ipep);
if (!(fd.Poll(1000000, SelectMode.SelectRead)))
{
Console.WriteLine("Timeout on answer!\n");
len = 0;
return;
}
else{
msg = new byte[2000];
len = fd.ReceiveFrom(msg, ref Remote);
}
}
unsafe static void Main()
{ capture_off(using send function above to send commands for the hardware to send );
Is the code correct? Do I need to do any preformatting of the data array before I send out? network byte order? Totally nuts about what is the problem source?
Pls advise. Many many thanks!!
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).