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

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)版權所有:易賢網
云南網警報警專用圖標
主站蜘蛛池模板: 巴彦县| 郧西县| 福安市| 巫溪县| 合山市| 筠连县| 呼伦贝尔市| 抚州市| 福泉市| 镇安县| 元阳县| 海盐县| 吉木乃县| 穆棱市| 曲阜市| 崇阳县| 舟曲县| 罗平县| 新蔡县| 乳源| 宁乡县| 青海省| 龙门县| 报价| 濉溪县| 宁远县| 油尖旺区| 靖西县| 民乐县| 恩施市| 邮箱| 荃湾区| 游戏| 呈贡县| 南召县| 荆州市| 怀仁县| 波密县| 塔河县| 沧源| 衡阳县|