Re: vb.net and sockets bug?



Hello,

1. Why are you creating the sockets two times?

2. Add a txSocket.Bind(new IPEndPoint(IPAddress.Any), 1234)

This will bind the socket to the local port 1234, and should solve your issue.

Best regards,
Henning Krause

"bucrepus" <bucrepus@xxxxxxxxxxxxxxxxxx> wrote in message news:%23OyWsVTdHHA.2088@xxxxxxxxxxxxxxxxxxxxxxx
Dim UpdateIP As IPAddress
Dim packet(2) As Byte
Dim txSocket As Socket = New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
'load some data of some sort
packet(0) = 1 : packet(0) = 1
UpdateIP = IPAddress.Parse("192.168.0.100")
txSocket = New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
Dim txPLCEP As New IPEndPoint(UpdateIP, 9001)
txSocket.SendTo(packet, txPLCEP)
txSocket.Close()
txSocket = Nothing

'packet is transmitted to 192.168.0.100 with a source dest port of 9001 and a source send port of 2039. Depending on the machine I test this code
on the source send port randomly changes around the 2000 range. verified with 2 diff packet sniffers including W2k3 server net monitor.

Thanks..
N\BUC




"buc" <bucrepus@xxxxxxxxxxxxxxxxxx> wrote in message news:uBnKlcKdHHA.2068@xxxxxxxxxxxxxxxxxxxxxxx
Why does VB.NET UDP sockets send data on random ports?. If I set a simple socket up to transmit a UDP packet on a port, look at the packet with a sniffer, the actual packets source port and dest.port are diff. The packets destination port is correct, but the packets source port it is actually sent from is random. Why? How can I figure out the actual source port windows is using, not what the vb.net socket is fake reporting?
Thanks BUC





.



Relevant Pages

  • Re: SetSockOpt with SO_REUSEADDR parameter
    ... If he is using UDP to send, then there is ONE UDP socket to do this, and all the ... connections send messages via this one-and-only UDP port. ... When using TCP, the source port number is usually totally irrelevant, what ... When a server accepts ...
    (microsoft.public.vc.mfc)
  • Re: Problem with socket
    ... Be aware that those port numbers are part of the IANA-assigned range. ... socket operations on sockets for which there are no handles... ... The result of using comma lists is ... you have used the completely meaningless word "crash" to describe your ...
    (microsoft.public.vc.mfc)
  • RE: call is blocked in recvfrom() and no further proceedings in Win CE
    ... In windows CE, I'm able to send a request but I'm unable to receive it. ... Create another socket & bind with server IP address. ... > My program has to send request to service through port 5070(in this port only ...
    (microsoft.public.windowsce.embedded)
  • Re: ISA Event
    ... applying ISA SP1 resolved the issue. ... So it's worth asking - is this SBS ... > Web Proxy service failed to bind its socket to 192.168.4.9 port 443. ...
    (microsoft.public.backoffice.smallbiz2000)
  • Re: Freebsd IP Forwarding performance (question, and some info) [7-stable, current, em, smp]
    ... INADDR_ANY and a specific port. ... sendtoon a specific address and port on a socket that has been bound to ... bogus exit code) and adds a sleep after send failure. ... unless HZ is too small or the queue is too large. ...
    (freebsd-net)