473,326 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Unreliable VB.NET Sockets

Buc
I have a small program that accepts a DGRAM UDP text packet (+-250 bytes
port 9001) and puts it in a list box. The network receive part acts BUGGY.
It acts the same way on more than one machine. It acted random.. SO..I used
the debugger, the callback fires and the first line of code breaks (the
receivefrom) and then the sub exits without executing the remaining lines of
code ?? The next packet may do the same thing OR the sub may finish the
remaining lines of code correctly and actually stick the text packet in the
listbox. I send one packet at a time for test and verify with a sniffer. I
added the try / catch later to see if there was some MYSTERY error but it
didn't catch anything either. (An Exception or a SocketException) Here's the
code...
Dim rxSocket As Socket = Nothing
Dim RecvBytes(1000) As Byte
Dim RemoteEP As New IPEndPoint(0, 0)

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
rxSocket = New Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp)
RemoteEP = New IPEndPoint(IPAddress.Any, 9001)
rxSocket.Bind(RemoteEP)
rxSocket.BeginReceiveFrom(RecvBytes, 0, RecvBytes.Length,
SocketFlags.None, RemoteEP, New AsyncCallback(AddressOf OnReceive), Nothing)
End Sub
Public Sub OnReceive(ByVal ar As IAsyncResult)
Dim iBytes As Integer
Try
iBytes = rxSocket.ReceiveFrom(RecvBytes, 0, RecvBytes.Length,
SocketFlags.None, RemoteEP) <<BREAKPOINT HERE and then it exits sub
SOMETIMES
Catch e As SocketException <<no Socket exception or other
exception occurs
MsgBox(e.Message)
Exit Sub
End Try
ListBox1.Items.Add(Encoding.UTF8.GetString(RecvByt es))
iBytes = rxSocket.EndReceiveFrom(ar, RemoteEP)
rxSocket.BeginReceiveFrom(RecvBytes, 0, RecvBytes.Length,
SocketFlags.None, RemoteEP, New AsyncCallback(AddressOf OnReceive), Nothing)
End Sub

Please Help, I don't know what else to except go back and use the MS Winsock
control with dot net somehow if I can't get dotnet SOCKET stuff to work
reliably..
Buc


Nov 20 '05 #1
2 3241
Buc
Never Mind, I took the RECEIVEFROM line out and it started getting every
packet, Its not needed I guess, any the data is already in Recvbytes buffer
when callback OnReceive fires..

"Buc" <bu******@hotmail.com> wrote in message
news:eQ**************@TK2MSFTNGP09.phx.gbl...
I have a small program that accepts a DGRAM UDP text packet (+-250 bytes
port 9001) and puts it in a list box. The network receive part acts BUGGY.
It acts the same way on more than one machine. It acted random.. SO..I used the debugger, the callback fires and the first line of code breaks (the
receivefrom) and then the sub exits without executing the remaining lines of code ?? The next packet may do the same thing OR the sub may finish the
remaining lines of code correctly and actually stick the text packet in the listbox. I send one packet at a time for test and verify with a sniffer. I
added the try / catch later to see if there was some MYSTERY error but it
didn't catch anything either. (An Exception or a SocketException) Here's the code...
Dim rxSocket As Socket = Nothing
Dim RecvBytes(1000) As Byte
Dim RemoteEP As New IPEndPoint(0, 0)

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
rxSocket = New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
RemoteEP = New IPEndPoint(IPAddress.Any, 9001)
rxSocket.Bind(RemoteEP)
rxSocket.BeginReceiveFrom(RecvBytes, 0, RecvBytes.Length,
SocketFlags.None, RemoteEP, New AsyncCallback(AddressOf OnReceive), Nothing) End Sub
Public Sub OnReceive(ByVal ar As IAsyncResult)
Dim iBytes As Integer
Try
iBytes = rxSocket.ReceiveFrom(RecvBytes, 0, RecvBytes.Length,
SocketFlags.None, RemoteEP) <<BREAKPOINT HERE and then it exits sub
SOMETIMES
Catch e As SocketException <<no Socket exception or other
exception occurs
MsgBox(e.Message)
Exit Sub
End Try
ListBox1.Items.Add(Encoding.UTF8.GetString(RecvByt es))
iBytes = rxSocket.EndReceiveFrom(ar, RemoteEP)
rxSocket.BeginReceiveFrom(RecvBytes, 0, RecvBytes.Length,
SocketFlags.None, RemoteEP, New AsyncCallback(AddressOf OnReceive), Nothing) End Sub

Please Help, I don't know what else to except go back and use the MS Winsock control with dot net somehow if I can't get dotnet SOCKET stuff to work
reliably..
Buc

Nov 20 '05 #2
Hi,

Try using a variable instead of using new in
rxSocket.beginreceievefrom.

Dim myCallback as New AsyncCallback(AddressOf OnReceive)
rxSocket.BeginReceiveFrom(RecvBytes, 0, RecvBytes.Length,
SocketFlags.None, RemoteEP, myCallback, Nothing)

Check out indy an open source dotnet sockets class.
http://www.indyproject.org/Indy.html

Ken
-------------------------

"Buc" <bu******@hotmail.com> wrote in message
news:eQ**************@TK2MSFTNGP09.phx.gbl...
I have a small program that accepts a DGRAM UDP text packet (+-250 bytes
port 9001) and puts it in a list box. The network receive part acts BUGGY.
It acts the same way on more than one machine. It acted random.. SO..I
used
the debugger, the callback fires and the first line of code breaks (the
receivefrom) and then the sub exits without executing the remaining lines
of
code ?? The next packet may do the same thing OR the sub may finish the
remaining lines of code correctly and actually stick the text packet in
the
listbox. I send one packet at a time for test and verify with a sniffer. I
added the try / catch later to see if there was some MYSTERY error but it
didn't catch anything either. (An Exception or a SocketException) Here's
the
code...
Dim rxSocket As Socket = Nothing
Dim RecvBytes(1000) As Byte
Dim RemoteEP As New IPEndPoint(0, 0)

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
rxSocket = New Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp)
RemoteEP = New IPEndPoint(IPAddress.Any, 9001)
rxSocket.Bind(RemoteEP)
rxSocket.BeginReceiveFrom(RecvBytes, 0, RecvBytes.Length,
SocketFlags.None, RemoteEP, New AsyncCallback(AddressOf OnReceive),
Nothing)
End Sub
Public Sub OnReceive(ByVal ar As IAsyncResult)
Dim iBytes As Integer
Try
iBytes = rxSocket.ReceiveFrom(RecvBytes, 0, RecvBytes.Length,
SocketFlags.None, RemoteEP) <<BREAKPOINT HERE and then it exits sub
SOMETIMES
Catch e As SocketException <<no Socket exception or other
exception occurs
MsgBox(e.Message)
Exit Sub
End Try
ListBox1.Items.Add(Encoding.UTF8.GetString(RecvByt es))
iBytes = rxSocket.EndReceiveFrom(ar, RemoteEP)
rxSocket.BeginReceiveFrom(RecvBytes, 0, RecvBytes.Length,
SocketFlags.None, RemoteEP, New AsyncCallback(AddressOf OnReceive),
Nothing)
End Sub

Please Help, I don't know what else to except go back and use the MS
Winsock
control with dot net somehow if I can't get dotnet SOCKET stuff to work
reliably..
Buc

Nov 20 '05 #3

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

Similar topics

2
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...
4
by: James R. Saker Jr. | last post by:
I see per pydoc that Queue.Queue()'s .qsize is allegedly unreliable: | qsize(self) | Return the approximate size of the queue (not reliable!). Any thoughts on why this is unreliable (and...
1
by: Eric McRae | last post by:
I have created a somewhat complicated GUI which updates itself every 1/2 second by checking on several non-blocking sockets for data and modifying StringVars and/or canvas graphs when new...
1
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...
4
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
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...
3
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...
7
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.