国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net使用Socket.Send發送信息及Socket.SendFile傳輸文件的方法

2024-07-10 12:47:00
字體:
來源:轉載
供稿:網友

本文實例講述了asp.net使用Socket.Send發送信息及Socket.SendFile傳輸文件的方法。,具體如下:

// Displays sending with a connected socket// using the overload that takes a buffer.public static int SendReceiveTest1(Socket server){  byte[] msg = Encoding.UTF8.GetBytes("This is a test");  byte[] bytes = new byte[256];  try  {    // Blocks until send returns.    int i = server.Send(msg);    Console.WriteLine("Sent {0} bytes.", i);    // Get reply from the server.    i = server.Receive(bytes);    Console.WriteLine(Encoding.UTF8.GetString(bytes));  }  catch (SocketException e)  {    Console.WriteLine("{0} Error code: {1}.", e.Message, e.ErrorCode);    return (e.ErrorCode);  }  return 0;}
// Establish the local endpoint for the socket.IPHostEntry ipHost = Dns.GetHostEntry(Dns.GetHostName());IPAddress ipAddr = ipHost.AddressList[0];IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, 11000);// Create a TCP socket.Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);// Connect the socket to the remote endpoint.client.Connect(ipEndPoint);// There is a text file test.txt located in the root directory.string fileName = "C://test.txt";// Send file fileName to remote deviceConsole.WriteLine("Sending {0} to the host.", fileName);client.SendFile(fileName);// Release the socket.client.Shutdown(SocketShutdown.Both);client.Close();

更多關于asp.net相關內容感興趣的讀者可查看本站專題:《asp.net操作json技巧總結》、《asp.net字符串操作技巧匯總》、《asp.net操作XML技巧總結》、《asp.net文件操作技巧匯總》、《asp.net ajax技巧總結專題》及《asp.net緩存操作技巧總結》。

希望本文所述對大家asp.net程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永新县| 高密市| 勃利县| 浮梁县| 天全县| 加查县| 乌兰浩特市| 盱眙县| 新营市| 柳州市| 新宁县| 汉寿县| 肇东市| 瓦房店市| 天祝| 土默特左旗| 永登县| 油尖旺区| 两当县| 丰宁| 敦煌市| 大埔县| 太谷县| 封丘县| 二连浩特市| 蕉岭县| 六盘水市| 南通市| 通城县| 普洱| 宁城县| 东安县| 巫山县| 铜梁县| 广南县| 卢湾区| 扎赉特旗| 江油市| 忻州市| 柘城县| 马尔康县|