473,396 Members | 1,813 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,396 software developers and data experts.

async UDP

I am having problems doing asyncronous UDP with VB.Net 2003. I am trying
to be always listening on port 7000 for incoming UDP packets and process
them with OnReceive, and at any time send data through the socket on port
7000 to any dest.

When I call sock.BeginReceive, I am unable to use sock.BeginSendTo/SentTo,
but if I don't call it, I can send without getting the following error.
You can see this in test()

Unhandled Exception: System.NullReferenceException: Object reference not
set to an instance of an object.
at System.Net.OSSOCK.WSAGetOverlappedResult(IntPtr socketHandle, IntPtr
overlapped, UInt32& bytesTransferred, Boolean wait, IntPtr ignored) at
System.Net.Sockets.OverlappedAsyncResult.Completio nPortCallback(UInt32
errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)

Can anyone give me advice on how to do this?
Thanks,

Dim sock As Socket
Dim buffer(1024 * 32) As Byte
Dim iasync As IAsyncResult

Sub test()
sock = New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
sock.Bind(New IPEndPoint(IPAddress.Parse("127.0.0.1"), 7000))

Dim d(1) As Byte : d(0) = 6
iasync = sock.BeginReceive(buffer, 0, buffer.Length, SocketFlags.Partial, New AsyncCallback(AddressOf OnReceive), Me)
sock.BeginSendTo(d, 0, 1, SocketFlags.None, New IPEndPoint(IPAddress.Parse("127.0.0.1"), 7001), New AsyncCallback(AddressOf OnSend), Me)
End Sub

Private Sub OnReceive(ByVal ar As IAsyncResult)
Dim bytesReceived As Integer = sock.EndReceive(ar)
Console.WriteLine("Data received")
End Sub

Sub OnSend(ByVal ar As IAsyncResult)
Console.WriteLine("Data was sent")
End Sub
Nov 21 '05 #1
2 3135
Hi Michael,

I thing you may try to take a look at the sample below to see if that helps
you.
UDP Echo Server and Client
http://www.gotdotnet.com/Community/U...mpleGuid=14ca4
759-3bff-4f06-9cce-69b00ae0b9c7

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #2
Hi Michael,

Did the link help you?
If you still have any concern on this issue, please feel free to let me
know.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #3

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

Similar topics

8
by: Dave | last post by:
I'm using the BeginInvoke method of a delegate to invoke a thread asynchronously and then use the EndInvoke to retrieve the value. This works wonderfully until a Serviced Component is added to...
6
by: Vanessa | last post by:
I have a question regarding async mode for calling Microsoft.XMLHTTP object. Microsoft.XMLHTTP hangs the IE once in a while suddenly, but it will work again after half an hour or so without doing...
0
by: Passynkov, Vadim | last post by:
I am using Asynchronous Query Processing interface from libpq library. And I got some strange results on Solaris My test select query is 'SELECT * from pg_user;' and I use select system...
10
by: Shawn Meyer | last post by:
Hello - I am trying to write a class that has an async BeginX and EndX, plus the regular X syncronous method. Delegates seemed like the way to go, however, I still am having problems getting...
8
by: TS | last post by:
Im in a web page and call an asynchronous method in business class. the call back method is in the web page. When page processes, it runs thru code begins invoking the method then the page...
1
by: Simon Hart | last post by:
Hi, I thought I'd just open a thread in an attempt to get peoples feelers with regards to multithreading vs Async Web Service processing. Of course Web Services makes it easy to do Async...
6
by: gabriel.landais | last post by:
Hi, I'm currently building a parser class in JS and I have a question about variables. I retrieve XML data and then process it. After that, I process a result array (mydataarray). It looks like...
6
by: Shak | last post by:
Hi all, Three questions really: 1) The async call to the networkstream's endread() (or even endxxx() in general) blocks. Async calls are made on the threadpool - aren't we advised not to...
7
by: Shak | last post by:
Hi all, I'm trying to write a thread-safe async method to send a message of the form (type)(contents). My model is as follows: private void SendMessage(int type, string message) { //lets...
10
by: Frankie | last post by:
It appears that System.Random would provide an acceptable means through which to generate a unique value used to identify multiple/concurrent asynchronous tasks. The usage of the value under...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.