中文字幕免费精品_亚洲视频自拍_亚洲综合国产激情另类一区_色综合咪咪久久

asp.net使用Socket.Send發送信息及Socket.SendFile傳輸文件的方法
來源:易賢網 閱讀:1014 次 日期:2016-08-05 15:33:46
溫馨提示:易賢網小編為您整理了“asp.net使用Socket.Send發送信息及Socket.SendFile傳輸文件的方法”,方便廣大網友查閱!

本文實例講述了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 device

Console.WriteLine("Sending {0} to the host.", fileName);

client.SendFile(fileName);

// Release the socket.

client.Shutdown(SocketShutdown.Both);

client.Close();

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

更多信息請查看網絡編程
由于各方面情況的不斷調整與變化,易賢網提供的所有考試信息和咨詢回復僅供參考,敬請考生以權威部門公布的正式信息和咨詢為準!

2026國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關于我們 | 聯系我們 | 人才招聘 | 網站聲明 | 網站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
工業和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
云南網警備案專用圖標
聯系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權所有:易賢網
云南網警報警專用圖標
主站蜘蛛池模板: 株洲市| 桐城市| 巫山县| 白城市| 池州市| 嘉黎县| 宁南县| 布拖县| 鸡东县| 阳城县| 丰台区| 驻马店市| 仪陇县| 温州市| 龙泉市| 晴隆县| 洪泽县| 仁布县| 宿松县| 钟山县| 田东县| 碌曲县| 安庆市| 沈阳市| 淄博市| 慈利县| 汉寿县| 社旗县| 蓝田县| 清丰县| 华安县| 浮梁县| 汾西县| 黔西县| 正定县| 宁晋县| 民和| 琼中| 四平市| 本溪| 任丘市|