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(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
rxSocket = New Socket(AddressF amily.InterNetw ork, SocketType.Dgra m,
ProtocolType.Ud p)
RemoteEP = New IPEndPoint(IPAd dress.Any, 9001)
rxSocket.Bind(R emoteEP)
rxSocket.BeginR eceiveFrom(Recv Bytes, 0, RecvBytes.Lengt h,
SocketFlags.Non e, RemoteEP, New AsyncCallback(A ddressOf OnReceive), Nothing)
End Sub
Public Sub OnReceive(ByVal ar As IAsyncResult)
Dim iBytes As Integer
Try
iBytes = rxSocket.Receiv eFrom(RecvBytes , 0, RecvBytes.Lengt h,
SocketFlags.Non e, RemoteEP) <<BREAKPOINT HERE and then it exits sub
SOMETIMES
Catch e As SocketException <<no Socket exception or other
exception occurs
MsgBox(e.Messag e)
Exit Sub
End Try
ListBox1.Items. Add(Encoding.UT F8.GetString(Re cvBytes))
iBytes = rxSocket.EndRec eiveFrom(ar, RemoteEP)
rxSocket.BeginR eceiveFrom(Recv Bytes, 0, RecvBytes.Lengt h,
SocketFlags.Non e, RemoteEP, New AsyncCallback(A ddressOf 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 2 3253
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******@hotma il.com> wrote in message
news:eQ******** ******@TK2MSFTN GP09.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(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load rxSocket = New Socket(AddressF amily.InterNetw ork,
SocketType.Dgra m, ProtocolType.Ud p) RemoteEP = New IPEndPoint(IPAd dress.Any, 9001) rxSocket.Bind(R emoteEP) rxSocket.BeginR eceiveFrom(Recv Bytes, 0, RecvBytes.Lengt h, SocketFlags.Non e, RemoteEP, New AsyncCallback(A ddressOf OnReceive),
Nothing) End Sub Public Sub OnReceive(ByVal ar As IAsyncResult) Dim iBytes As Integer Try iBytes = rxSocket.Receiv eFrom(RecvBytes , 0, RecvBytes.Lengt h, SocketFlags.Non e, RemoteEP) <<BREAKPOINT HERE and then it exits sub SOMETIMES Catch e As SocketException <<no Socket exception or other exception occurs MsgBox(e.Messag e) Exit Sub End Try ListBox1.Items. Add(Encoding.UT F8.GetString(Re cvBytes)) iBytes = rxSocket.EndRec eiveFrom(ar, RemoteEP) rxSocket.BeginR eceiveFrom(Recv Bytes, 0, RecvBytes.Lengt h, SocketFlags.Non e, RemoteEP, New AsyncCallback(A ddressOf 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
Hi,
Try using a variable instead of using new in
rxSocket.beginr eceievefrom.
Dim myCallback as New AsyncCallback(A ddressOf OnReceive)
rxSocket.BeginR eceiveFrom(Recv Bytes, 0, RecvBytes.Lengt h,
SocketFlags.Non e, RemoteEP, myCallback, Nothing)
Check out indy an open source dotnet sockets class. http://www.indyproject.org/Indy.html
Ken
-------------------------
"Buc" <bu******@hotma il.com> wrote in message
news:eQ******** ******@TK2MSFTN GP09.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(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load rxSocket = New Socket(AddressF amily.InterNetw ork, SocketType.Dgra m, ProtocolType.Ud p) RemoteEP = New IPEndPoint(IPAd dress.Any, 9001) rxSocket.Bind(R emoteEP) rxSocket.BeginR eceiveFrom(Recv Bytes, 0, RecvBytes.Lengt h, SocketFlags.Non e, RemoteEP, New AsyncCallback(A ddressOf OnReceive), Nothing) End Sub Public Sub OnReceive(ByVal ar As IAsyncResult) Dim iBytes As Integer Try iBytes = rxSocket.Receiv eFrom(RecvBytes , 0, RecvBytes.Lengt h, SocketFlags.Non e, RemoteEP) <<BREAKPOINT HERE and then it exits sub SOMETIMES Catch e As SocketException <<no Socket exception or other exception occurs MsgBox(e.Messag e) Exit Sub End Try ListBox1.Items. Add(Encoding.UT F8.GetString(Re cvBytes)) iBytes = rxSocket.EndRec eiveFrom(ar, RemoteEP) rxSocket.BeginR eceiveFrom(Recv Bytes, 0, RecvBytes.Lengt h, SocketFlags.Non e, RemoteEP, New AsyncCallback(A ddressOf 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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 more curiously, why it would
be put in there as an unreliable function?) Rather than roll my own
threaded fifo class, it would seem prudent to use Python's built-in
Queue but the warning signs on a rather necessary function seem curious.
|
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 information is
present.
The basic structure is:
======
from Tkinter import *
top=Tk()
|
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.
|
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
| |
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...
|
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
|
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)
|
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...
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |