Building High Throughput, Multi-threaded Servers in C#NET文档.pptVIP

  • 3
  • 0
  • 约1.81万字
  • 约 51页
  • 2018-02-27 发布于湖北
  • 举报

Building High Throughput, Multi-threaded Servers in C#NET文档.ppt

Building High Throughput, Multi-threaded Servers in C#NET文档

using System; using System.Text; using System.Net; using System.Net.Sockets; namespace EchoServer { class Program { static void Main(string[] args) { try { . . . } catch(Exception x) { Console.WriteLine(x.ToString()); } } } } UDP Echo Server – the shell * UDP Echo Server – the code try { // create a udp server on port 8666 UdpClient server = new UdpClient(8666); // create an end point that maps to any ip and any port IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, 0); // receive data from our end point byte[] data = server.Receive(ref endPoint); // convert from bytes to string string msg = Encoding.ASCII.GetString(data); // display the message and who it is from Console.WriteLine( Received message from {0} == {1}, endPoint.ToString(), msg); } * UDP Echo Client in Java public static void main(String[] args) { try { // set up our locals InetAddress host = InetAddress.getByName(); int port = 8666; String msg = Hello World from Java; // get the bytes for string byte[] data = msg.getBytes(); // create a udp client DatagramSocket client = new DatagramSocket(); // create our data packet DatagramPacket packet = new DatagramPacket(data, data.length, host, port); // send the data client.send(packet); } catch(Exception x) { System.out.println(x.toString()); }; } * UDP Echo Client in C# static void Main(string[] args) { // set up locals string hostname = ; int port = 8666; string msg = Hello World from C#; try { // get ascii bytes for our message byte[] data = Encoding.ASCII.GetBytes(msg); // create a udp client UdpClient client = new UdpClient(); // send the bytes to a udp listener client.Send(data, data.Length, hostname, port); } catch(Exception x) { Console.WriteLine(x.T

文档评论(0)

1亿VIP精品文档

相关文档