Hey all. I’m having an issue with c# and it quite possibly may be the debugger but I’m fairly new to c# (not new to c/c++)
There’s code below. Here is the issue I’m having.
I get UDP, not guaranteed delivery, sure. I expect that the occasional packet is dropped on the network or by windows if I’m stuffing the pipe full. However, the problem I am having is that after I create a new socket, I try and send a packet with 1 byte of data. This packet is dropped. I can try and send it twice, it’s dropped both times. However, if I send 1k worth of data, it goes through. If I create another socket (by clicking the button again), everything works fine. Now here’s the weird thing. If I stop and restart debugging the project without making any changes to the source, all my packets get sent without problems. It only seems to happen the on the first run after the project is built. Anyway, here’s the code to reproduce the issue. After a few hours of searching and reading I’m at a loss.
edit: Wanted to clarify that I’m using wireshark and can see that the packets are dropped.
private void button1_Click(object sender, EventArgs e)
{
byte[] a = new byte[1] {0x00};
byte[] b = new byte[1024];
for(int i = 0; i < 1024; i++)
{
b[i] = 0xFF;
}
IPEndPoint _ipep = new IPEndPoint(IPAddress.Parse("192.168.200.202"),5546);
Socket _server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
_server.SendTo(a, 1, SocketFlags.None, _ipep);
_server.SendTo(a, 1, SocketFlags.None, _ipep);
_server.SendTo(b, 1024, SocketFlags.None, _ipep);
}
From your comment about ARP issue, I would like to suggest some ways to debug and narrow down the issue and then suggest some solutions.
How to Debug:
Try making the ARP entry “static” so
that your PC do not send ARP request
each time. To make ARP entry static
you can write “arp” on command
prompt to see the list of options
and help to add static ARP entry.
Another idea is to open the command
prompt and write “ping
192.168.200.202 -t”, so that your PC keeps on pinging the other client.
This will keep your PC’s ARP entry
up to date and when you will run
your C# program, it will not send
ARP again, and it will directly send
the UDP.
The above points are just to debug and ensure that you guessed the problem right.
The Possible Solutions:
I hope it helps.