PC Review


Reply
Thread Tools Rate Thread

vb.net and sockets bug?

 
 
Henning Krause [MVP - Exchange]
Guest
Posts: n/a
 
      1st Apr 2007
Hello,

have you bound your local socket to an explicit port?

Dim socket as Socket

socket = new Socket(...)

socket.Bind(new IPEndPoint(IPAddress.Any), port_number)

Best regards,
Henning Krause

"buc" <(E-Mail Removed)_remove> wrote in message
news:(E-Mail Removed)...
> 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
>
>


 
Reply With Quote
 
 
 
 
buc
Guest
Posts: n/a
 
      1st Apr 2007
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


 
Reply With Quote
 
 
 
 
buc
Guest
Posts: n/a
 
      2nd Apr 2007
Yes, I bind to a port, for example 9001, and 9001 is placed into the packet
as the destination port, but the source send port is in the 2000 range. This
appears to be a bug, and is easily reproducable with only a few lines of
code. Even example code from the MSDN. I tried the same code on XP or 2003
server platform with the same results.
BUC

"buc" <(E-Mail Removed)_remove> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Henning Krause [MVP - Exchange]
Guest
Posts: n/a
 
      2nd Apr 2007
Hello,

please post your code here.

Best regards,
Henning Krause

"buc" <(E-Mail Removed)_remove> wrote in message
news:%23$(E-Mail Removed)...
> Yes, I bind to a port, for example 9001, and 9001 is placed into the
> packet as the destination port, but the source send port is in the 2000
> range. This appears to be a bug, and is easily reproducable with only a
> few lines of code. Even example code from the MSDN. I tried the same code
> on XP or 2003 server platform with the same results.
> BUC
>
> "buc" <(E-Mail Removed)_remove> wrote in message
> news:(E-Mail Removed)...
>> 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
>>
>>

>
>


 
Reply With Quote
 
bucrepus
Guest
Posts: n/a
 
      2nd Apr 2007
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" <(E-Mail Removed)_remove> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Henning Krause [MVP - Exchange]
Guest
Posts: n/a
 
      2nd Apr 2007
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" <(E-Mail Removed)_remove> wrote in message
news:%(E-Mail Removed)...
> 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" <(E-Mail Removed)_remove> wrote in message
> news:(E-Mail Removed)...
>> 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
>>
>>

>
>


 
Reply With Quote
 
bucrepus
Guest
Posts: n/a
 
      2nd Apr 2007
Sorry about the double creation. Changing the bind to 1234 does bind PART of
the local port 1234. If I issue a sendto as in my code Sendto(...,1234), the
actual setup of the packet from vb.net shows a send source port of 2011 and
a send dest port of 1234. which is only halfway correct, as verified by
windows network monitor. This is def. a BUG.
I am trying to do something simple. I send to a remote machine(nonwindows)
with a simple UDP packet. I used the code to send 2 bytes of data on port
9001. The remote receives the data but transmits a packet back to me on the
REAL send source port the VB program sent it on which is NOT 9001, it looks
like a windows assigned port. In fact the MSDN says it if you dont assign
the SEND SOURCE PORT for the packet , it will assign a port in the
2000-65535 range. VB is only setting the dest port part of the packet, not
the source send port part of it. I you actually fired the code off and
lookup at it with a sniffer, this happens every time. I am very
frustrated.Since windows is assigning a random port, I cant use the bind to
figure out what port to listen on. Using a sniffer it is easy to see this
bug, using MSDN code or mine, Ive tried several examples from MSDN with same
results.
Any more ideas?
Thanks BUC

"Henning Krause [MVP - Exchange]" <(E-Mail Removed)>
wrote in message news:(E-Mail Removed)...
> 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" <(E-Mail Removed)_remove> wrote in message
> news:%(E-Mail Removed)...
>> 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" <(E-Mail Removed)_remove> wrote in message
>> news:(E-Mail Removed)...
>>> 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
>>>
>>>

>>
>>

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Async sockets vs synch sockets and threads nyhetsgrupper@gmail.com Microsoft C# .NET 4 20th Sep 2006 04:06 AM
Sockets and binding sockets piotrek Microsoft C# .NET 0 28th Sep 2005 08:17 PM
System.Net.Sockets.TcpClient and System.Net.Sockets.TcpListener. Handling errors Claire Microsoft C# .NET 1 2nd Aug 2005 12:45 PM
Sockets Server / Sockets Client - unable to read data from the transport connection Mike Dole Microsoft Dot NET 4 6th Jun 2004 07:18 PM
When do I use System.Net.Sockets.TcpClient and System.Net.Sockets.Socket? BadOmen Microsoft VB .NET 4 5th Mar 2004 07:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:42 PM.