473,385 Members | 1,846 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 with UdpClient

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 missing part is the server.

Tia.
Nov 16 '05 #1
4 5136
I've tried everything to get this sample to work but I never receive
anything. Both pc-s are connected ok; ping works both ways and a udp test
program gets messages across both ways. When I use the Send method I get
messages to the other pc fine. Receive only gives me trouble. I copied the
example from HELP. It throws an exception telling me I 'm feeding it an
invalid argument...

It all looked straight forward but I'm getting desparate

Peter

"Emilio" wrote:
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 missing part is the server.

Tia.

Nov 16 '05 #2
Plem,

Please include your source...

I would suggest not using UdpClient due to a timeout not being able to
be set
in the receive method..The receive call has to be in a thread worker,
which needs
to be aborted in a timeout situation.

David.

Nov 16 '05 #3
Plem,

Please include your source...

I would suggest not using UdpClient due to a timeout not being able to
be set
in the receive method..The receive call has to be in a thread worker,
which needs
to be aborted in a timeout situation.

David.

Nov 16 '05 #4
David,

Good idea...

The code below is a sample from the VS help... very straight forward. No
default host is set with the connect method so it should receive from any
host... it doesn't

It bangs out saying:
---------
System.Net.Sockets.SocketException: Invalid Argument
at System.Net.Sockets.Socket.ReceiveFrom(Byte[] buffer, Int32 offset,
Int32 size, SocketFlags socketFlags, EndPoint& remoteEP)
at System.Net.Sockets.Socket.ReceiveFrom(Byte[] buffer, Int32 size,
SocketFlags socketFlags, EndPoint& remoteEP)
at System.Net.Sockets.UdpClient.Receive(IPEndPoint& remoteEP)
---------

********
Private Function MicrosoftSample() As Integer
'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 Function
*******

If I create an instance of an IPEndpoint and set it to the remotehost, this
occurs just the same. If I first use the connect method to set the default
host, the code hangs in the receive method as if there is nothing to receive.
(I KNOW that is not true)

Peter
"da*********@europe.com" wrote:
Plem,

Please include your source...


Nov 16 '05 #5

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

Similar topics

0
by: Stephan Steiner | last post by:
Hi The project I'm currently working on involves sending large UDP broadcasts. As the .NET framework already provides an easy facility for sending and receiving UDP packets I thought it was a...
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: goodmannewz | last post by:
I just cannot run the sample code from msdn. Please tell me why? Thanks a lot. I create a console C# project, parsed the example codes: public class UDPMulticastListener { private static...
1
by: Plem | last post by:
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...
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,...
0
by: tccode97 | last post by:
To whom it may concern, I am developing a socket application in VC++ that uses asynchronous connnection. After doing search on google, I found the following link ...
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 ...
1
by: Jerry Spence1 | last post by:
I have the following piece of code: Dim udpClient As New UdpClient Dim MyData = "1234567890ABC" udpClient.Connect("255.255.255.255", 999) Dim sendBytes As () = Encoding.ASCII.GetBytes(MyData)...
0
by: matt | last post by:
Hi I built a class to poll an app on a udp port using the sync methods which worked fine. I've since changed to using beginreceive and now the poll works but I don't receive the response from...
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) {
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?

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.