•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 426,463 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,237 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser: Programming Forums
Views: 1738 | Replies: 6
![]() |
•
•
Join Date: Nov 2006
Location: Bonners Ferry, ID
Posts: 280
Reputation:
Rep Power: 2
Solved Threads: 39
•
•
Join Date: Nov 2006
Location: Bonners Ferry, ID
Posts: 280
Reputation:
Rep Power: 2
Solved Threads: 39
Selecting the UDP protocol is very similar to selecting Tcp, Echo, Ftp, etc etc. You will find plenty of examples of using UDP in the book.
Example:
J
Example:
Socket sock = new Socket(AddressFamily.Internetwork, SocketType.Dgram, ProtocolType.Udp);
J
c# Syntax (Toggle Plain Text) -
- using System;
- using System.Net;
- using System.Net.Sockets;
- using System.Text;
-
- public class SimpleUdpClient
- {
- public static void Main()
- {
- byte[] data = new byte[1024];
- string input, stringData;
- IPEndPoint ipep = new IPEndPoint(
- IPAddress.Parse("127.0.0.1"), 9050);
-
- Socket server = new Socket(AddressFamily.InterNetwork,
- SocketType.Dgram, ProtocolType.Udp);
-
-
- string welcome = "Hello, are you there?";
- data = Encoding.ASCII.GetBytes(welcome);
- server.SendTo(data, data.Length, SocketFlags.None, ipep);
-
- IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
- EndPoint Remote = (EndPoint)sender;
-
- data = new byte[1024];
- int recv = server.ReceiveFrom(data, ref Remote);
-
- Console.WriteLine("Message received from {0}:", Remote.ToString());
- Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
-
- while(true)
- {
- input = Console.ReadLine();
- if (input == "exit")
- break;
- server.SendTo(Encoding.ASCII.GetBytes(input), Remote);
- data = new byte[1024];
- recv = server.ReceiveFrom(data, ref Remote);
- stringData = Encoding.ASCII.GetString(data, 0, recv);
- Console.WriteLine(stringData);
- }
- Console.WriteLine("Stopping client");
- server.Close();
- }
- }
my main question is in line 13-14 does that line tell the device what IP to listen for or is that what IP to listen on?
![]() |
•
•
•
•
•
•
•
•
DaniWeb C# Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- IIS failing to start sites (Windows NT / 2000 / XP / 2003)
- Renew and Release IP Addresses (Windows tips 'n' tweaks)
- how to create a software package on tours and travels ? (Computer Science and Software Design)
- Looking to start a forum. (Growing an Online Community)
- For some reason program installations cannot create new start menu shortcuts... (Windows NT / 2000 / XP / 2003)
- about:blank virus (Viruses, Spyware and other Nasties)
- Can't delete three .tmp files (Windows 9x / Me)
- Action listeners (Java)
- Cant boot tecra8100 after deleting partition (Windows NT / 2000 / XP / 2003)
Other Threads in the C# Forum
- Previous Thread: HttwWebRequest.GetResponse not responding
- Next Thread: How to update a database?



Linear Mode