473,385 Members | 2,044 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,385 software developers and data experts.

Need help on UDPclient.receive

Hi All,

I've allready posted this on the C# group (oops).

I'm trying to get a UDPclient to receive. I use the sample code provided in
HELP but to nbo avail. When the receive method is executed, it throws an
exception, claiming an invalid argument was used. The WinAPI description on
MSDN says:

Invalid argument.
Some invalid argument was supplied (for example, specifying an invalid level
to the setsockopt function). In some instances, it also refers to the current
state of the socket—for instance, calling accept on a socket that is not
listening.

which doesn't get me any further. I don't get it.

Please HELP,

Peter

Sample Code:

'Creates a UdpClient for reading incoming data.
Dim receivingUdpClient As New UdpClient()

'Creates an IPEndPoint to record the IP address and port number of the
sender.
' The IPEndPoint will allow you to read datagrams sent from any source.
Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
Try

' Blocks until a message returns on this socket from a remote host.
Dim receiveBytes As [Byte]() = receivingUdpClient.Receive(RemoteIpEndPoint)

Dim returnData As String = Encoding.ASCII.GetString(receiveBytes)

Console.WriteLine(("This is the message you received " +
returnData.ToString()))
Console.WriteLine(("This message was sent from " +
RemoteIpEndPoint.Address.ToString() + " on their port number " +
RemoteIpEndPoint.Port.ToString()))
Catch e As Exception
Console.WriteLine(e.ToString())
End Try
End Sub 'MyUdpClientCommunicator
Nov 21 '05 #1
1 2141
I found a workaround: use sockets and screw the UDPclient

just great....

Peter (Plem)

"Plem" wrote:
Hi All,

I've allready posted this on the C# group (oops).

I'm trying to get a UDPclient to receive. I use the sample code provided in
HELP but to nbo avail. When the receive method is executed, it throws an
exception, claiming an invalid argument was used. The WinAPI description on
MSDN says:

Invalid argument.
Some invalid argument was supplied (for example, specifying an invalid level
to the setsockopt function). In some instances, it also refers to the current
state of the socket—for instance, calling accept on a socket that is not
listening.

which doesn't get me any further. I don't get it.

Please HELP,

Peter

Sample Code:

'Creates a UdpClient for reading incoming data.
Dim receivingUdpClient As New UdpClient()

'Creates an IPEndPoint to record the IP address and port number of the
sender.
' The IPEndPoint will allow you to read datagrams sent from any source.
Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
Try

' Blocks until a message returns on this socket from a remote host.
Dim receiveBytes As [Byte]() = receivingUdpClient.Receive(RemoteIpEndPoint)

Dim returnData As String = Encoding.ASCII.GetString(receiveBytes)

Console.WriteLine(("This is the message you received " +
returnData.ToString()))
Console.WriteLine(("This message was sent from " +
RemoteIpEndPoint.Address.ToString() + " on their port number " +
RemoteIpEndPoint.Port.ToString()))
Catch e As Exception
Console.WriteLine(e.ToString())
End Try
End Sub 'MyUdpClientCommunicator

Nov 21 '05 #2

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

Similar topics

4
by: Morten Overgaard | last post by:
Hi I'm listening on the SysLog port (514) through UDP. The problem is that I am not receiving anything nut I know that i get messages on the port. When I use KIWI to listen on the same port via...
2
by: Serdar C. | last post by:
im trying to write a really simple program that communicates with udp packets between server and client apps... but i cant receive (or send?) any data from any of the applications.. what am i doin...
4
by: Emilio | last post by:
In the help pages for the UdpClient there is some sample code which sends a udp message and prints what it received. Can someone help me to finish the code present there? I think basically the...
0
by: Steve | last post by:
I am looking into UdpClient sample code from MSDN where one UdpClient object used for both send and receive operation. Please take a look at the link below...
3
by: D. André Dhondt | last post by:
In VB.NET 2003, is there a way to create a System.Net.Sockets.UDPClient to listen to any address AND any port? I can get it to listen to any address, but only if I specify a port (for example,...
1
by: tccode97 | last post by:
Hi, I need an urgent help. I am developing a socket application in VC++ that uses asynchronous connnection. After doing search on google, I found the following link ...
2
by: ssmulgund | last post by:
What I'm trying to do seems pretty simple on the face of it -- create a UDP listener on a particular port. My code is as follows: int port = 9000; IPEndPoint endPoint = new...
7
by: | last post by:
I have the following program using System; using System.Collections; using System.Net.Sockets; using System.Net; using System.IO; public class Test { public static void Main(string s) {
0
by: Johan | last post by:
Suppose: There are two devices on my network that both broadcast UDP datagrams (and they both use the same portnumber 1234). I want to create two executables that use UdpClient internally. Each...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.