- 3
- 0
- 约1.81万字
- 约 51页
- 2018-02-27 发布于湖北
- 举报
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
您可能关注的文档
- amk_柴油发动机高级培训资料文档.ppt
- 9、东西方园林艺术的差异 - 2013年西安交通大学《艺术美学》ppt课件文档.ppt
- Appendix4风险(新业务)投资管理办法文档.ppt
- ARM监控系统投标书文档.ppt
- arb治疗糖尿病肾病的循证医学证据 ppt课件文档.ppt
- Auto CAD机械制图基础教程课件第02章文档.ppt
- an__en_in_un_vn课件新的1文档.ppt
- Auto CAD机械制图基础教程课件第01章文档.ppt
- AUTOCAD2007教程PPT版 第1章 AutoCAD 2007入门基础文档.ppt
- APC服务器机房解决方案文档.ppt
- 小区绿化施工协议书.docx
- 墙面施工协议书.docx
- 1 古诗二首(课件)--2025-2026学年统编版语文二年级下册.pptx
- (2026春新版)部编版八年级道德与法治下册《3.1《公民基本权利》PPT课件.pptx
- (2026春新版)部编版八年级道德与法治下册《4.3《依法履行义务》PPT课件.pptx
- (2026春新版)部编版八年级道德与法治下册《6.2《按劳分配为主体、多种分配方式并存》PPT课件.pptx
- (2026春新版)部编版八年级道德与法治下册《6.1《公有制为主体、多种所有制经济共同发展》PPT课件.pptx
- 初三教学管理交流发言稿.docx
- 小学生课外阅读总结.docx
- 餐饮门店夜经济运营的社会责任报告(夜间贡献)撰写流程试题库及答案.doc
原创力文档

文档评论(0)