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

UDPClient and my mental situaton.. Please Help

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 wrong? here are the
send and receive lines from my program:
Server:
ofcourse this void is in a system.thread and in a loop
---------------------------------------------------------
IPEndPoint endpoint = new IPEndPoint(IPAddress.Any,2000);
try
{
while(true)
{
byte[] x = client.Receive(ref endpoint);
string s = Encoding.ASCII.GetString(x);
status.Text = s;
}
}
catch (Exception e)
{status.Text += e.ToString();}
----------------------------------------------------------
and the client is:
----------------------------------------------------------
UdpClient udpclient = new UdpClient();
IPEndPoint ipend2 = new
IPEndPoint(IPAddress.Parse("127.0.0.1"),2000);
byte[] sendbyte = Encoding.ASCII.GetBytes(textBox1.Text);
try
{
udpclient.Send(sendbyte,sendbyte.Length,ipend2);
}
catch(Exception exc)
{status.Text +=exc.ToString();}
----------------------------------------------------------
so whats wrong ? please help!
Nov 15 '05 #1
2 1291
i forgot to write a line on the server app.:
-----------------------------------
udpclient client = new udpclient();
-----------------------------------
Nov 15 '05 #2
<an*******@discussions.microsoft.com> wrote in message news:<02****************************@phx.gbl>...
i forgot to write a line on the server app.:
-----------------------------------
udpclient client = new udpclient();
-----------------------------------

If this is how the line is in your server app, then you did not
Bind() the local UDP socket to a specific port. It will not know what
UDP packets to accept. If you want your server to accept packets on
UDP port 2000, it should look something like this:

IPEndPoint iep = new IPEndPoint(IPAddress.Any, 2000);
UdpClient client = new UdpClient(iep);
byte[] data = new byte[1024];
IPEndPoint iep2 = new IPEndPoint(IPAddress.Any, 0);
data = client.Receive(ref iep2);
Console.WriteLine("The remote host is: {0}, port {1}",
iep2.Address, iep2.Port);
Console.WriteLine("The data is: {0}",
Encoding.ASCII.GetString(data));

When you call the Receive() method with an IPEndPoint object, it
is used to hold the address of the remote host sending the data, not
the local address.

Hope this helps solve your problem.

Rich Blum - Author
"C# Network Programming" (Sybex)
http://www.sybex.com/sybexbooks.nsf/Booklist/4176
"Network Performance Open Source Toolkit" (Wiley)
http://www.wiley.com/WileyCDA/WileyT...471433012.html
Nov 15 '05 #3

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...
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...
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: Steve | last post by:
Please take a look at the simple code segment below and advise me what is wrong. According to the help and examples I've seen it should work unless I misunderstand something. The problem is...
2
by: Emilio | last post by:
Question about UdpClient sample ' This constructor arbitrarily assigns the local port number. Dim udpClient As New UdpClient() Try udpClient.Connect("www.contoso.com", 11000) ' Sends a...
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...
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 ...
0
by: yvz | last post by:
hi !! im a beginner in C# .... here is my problem ... i have 2 classes : 1. start an udpclient listener : "Form1" 2. display a Taskbar Notifier windows : "TaskbarNotifier" i need 2 diaplay...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
Oralloy
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,...
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,...
0
isladogs
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...

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.