473,725 Members | 2,118 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

vb.net and sockets bug?

buc
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
Apr 1 '07 #1
6 3121
Hello,

have you bound your local socket to an explicit port?

Dim socket as Socket

socket = new Socket(...)

socket.Bind(new IPEndPoint(IPAd dress.Any), port_number)

Best regards,
Henning Krause

"buc" <bu******@hotma il.com_removewr ote in message
news:uB******** ******@TK2MSFTN GP06.phx.gbl...
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

Apr 1 '07 #2
buc
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" <bu******@hotma il.com_removewr ote in message
news:uB******** ******@TK2MSFTN GP06.phx.gbl...
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


Apr 2 '07 #3
Hello,

please post your code here.

Best regards,
Henning Krause

"buc" <bu******@hotma il.com_removewr ote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
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" <bu******@hotma il.com_removewr ote in message
news:uB******** ******@TK2MSFTN GP06.phx.gbl...
>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


Apr 2 '07 #4
Dim UpdateIP As IPAddress
Dim packet(2) As Byte
Dim txSocket As Socket = New Socket(AddressF amily.InterNetw ork,
SocketType.Dgra m, ProtocolType.Ud p)
'load some data of some sort
packet(0) = 1 : packet(0) = 1
UpdateIP = IPAddress.Parse ("192.168.0.100 ")
txSocket = New Socket(AddressF amily.InterNetw ork, SocketType.Dgra m,
ProtocolType.Ud p)
Dim txPLCEP As New IPEndPoint(Upda teIP, 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" <bu******@hotma il.com_removewr ote in message
news:uB******** ******@TK2MSFTN GP06.phx.gbl...
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


Apr 2 '07 #5
Hello,

1. Why are you creating the sockets two times?

2. Add a txSocket.Bind(n ew IPEndPoint(IPAd dress.Any), 1234)

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

Best regards,
Henning Krause

"bucrepus" <bu******@hotma il.com_removewr ote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
Dim UpdateIP As IPAddress
Dim packet(2) As Byte
Dim txSocket As Socket = New Socket(AddressF amily.InterNetw ork,
SocketType.Dgra m, ProtocolType.Ud p)
'load some data of some sort
packet(0) = 1 : packet(0) = 1
UpdateIP = IPAddress.Parse ("192.168.0.100 ")
txSocket = New Socket(AddressF amily.InterNetw ork, SocketType.Dgra m,
ProtocolType.Ud p)
Dim txPLCEP As New IPEndPoint(Upda teIP, 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" <bu******@hotma il.com_removewr ote in message
news:uB******** ******@TK2MSFTN GP06.phx.gbl...
>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


Apr 2 '07 #6
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(nonwind ows)
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.Sinc e 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]" <ne************ ***@this.infini tec.de>
wrote in message news:u1******** ******@TK2MSFTN GP05.phx.gbl...
Hello,

1. Why are you creating the sockets two times?

2. Add a txSocket.Bind(n ew IPEndPoint(IPAd dress.Any), 1234)

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

Best regards,
Henning Krause

"bucrepus" <bu******@hotma il.com_removewr ote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
>Dim UpdateIP As IPAddress
Dim packet(2) As Byte
Dim txSocket As Socket = New Socket(AddressF amily.InterNetw ork,
SocketType.Dgr am, ProtocolType.Ud p)
'load some data of some sort
packet(0) = 1 : packet(0) = 1
UpdateIP = IPAddress.Parse ("192.168.0.100 ")
txSocket = New Socket(AddressF amily.InterNetw ork, SocketType.Dgra m,
ProtocolType.U dp)
Dim txPLCEP As New IPEndPoint(Upda teIP, 9001)
txSocket.SendT o(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" <bu******@hotma il.com_removewr ote in message
news:uB******* *******@TK2MSFT NGP06.phx.gbl.. .
>>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



Apr 2 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3893
by: Tero Saarni | last post by:
Hi, I have several threads communicating with each other using events stored in Queues. Threads block on Queue.get() until somebody publishes an event in thread's event queue. I need to add support for sockets to the system. Thread needs to unblock when: - there is socket ready to be read, or
1
3789
by: Dmitry Akselrod | last post by:
Hello everyone, I have a vb.net application that wraps the TCPListener object in a class. The server connects to the local interface and establishes itself on port 9900. It then polls for pending connections every 500ms. I also have a vb6 application that uses the WinSock control at the other end of the communication tunel. I have to work with vb6 here because it uses less memory than .NET.
0
1827
by: mrpolitics | last post by:
So I'm working with PureIRCD (http://sourceforge.net/projects/pure-ircd) and everything was fine untill yesterday when the server crashed. So I did a cold restart and staretd the server back up now it's throwing this stream of errors right away. Does anyone have any idea what they mean. I havn't changed the source at all since it was working (which was for four days). It errors here saying An unhandled exception of type...
3
10397
by: Logan McKinley | last post by:
I have a C# program that uses blocking sockets and want to allow the user to stop the server. The problem I am having is the socket blocks on -------------------------------------------------------------- listener = new System.Net.Sockets.TcpListener(6254); listener.Start(); //skt is a socket skt =listener.AcceptSocket(); <--- this line blocks -------------------------------------------------------------- I attempt to stop the thread...
1
20317
by: Adam Clauss | last post by:
I am (attempting) to move an existing socket application to use raw sockets. Right now, my application is essentially a port forwarder. Upon receiving a connection, it will open a connection to an "internal" server and simply relay all information back and forth (when the client sends something, my app sends that to the server, when server sends something, my app sends that to the client). While what I have right DOES work, the...
4
6318
by: BadOmen | last post by:
Hi, What is the different between 'System.Net.Sockets.Socket' and 'System.Net.Sockets.TcpClient'? When do I use System.Net.Sockets.TcpClient and System.Net.Sockets.Socket?? Yours, Jonas
3
4356
by: Michael Maercker | last post by:
hi! i'm really not into networking at all and have now been asigned the task of porting a vb6-code into vb.net (compact framework, in this case) and the code uses the winsock-control. i quickly found out that .net uses system.net.sockets.socket or .tcpclient/.tcpserver. and these confuse me... :o| and help would be really great! links, code, wrappers, tips, whateveryougot... one of my main problems, i guess, is: why don't sockets...
3
11588
by: J C | last post by:
Hi, I'm using UDPClient to make a simple DNS server. I notice that intermittently and unpredictibly I get: Unhandled Exception: System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.ReceiveFrom(Byte buffer, Int32 offset, Int32 s
7
6722
by: Adam01 | last post by:
Im using cygwin to test the code of a server I am writing. I've included sys/types.h, sys/socket.h, netdb.h, and arpa/inet.h. And this is the output.. ../../../sockets.cpp: In constructor `network_class::network_class()': ../../../sockets.cpp:64: error: aggregate `addrinfo hints' has incomplete type a nd cannot be defined ../../../sockets.cpp:69: error: `getaddrinfo' undeclared (first use this functio n)
0
8888
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9176
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9113
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.