第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

socket網(wǎng)絡(luò)編程問題

socket網(wǎng)絡(luò)編程問題

C#
qq_殺意隆_0 2018-03-17 10:51:49
服務(wù)端:using?System; using?System.IO; using?System.Collections; using?System.Collections.Generic; using?System.Configuration; using?System.Data.SqlClient; using?System.Text.RegularExpressions; using?MyLibrary; using?System.ComponentModel; using?System.Text; using?System.Security.Cryptography; using?Microsoft.International.Converters.PinYinConverter; using?System.Reflection; using?System.Net; using?System.Net.Sockets; using?System.Threading; namespace?first_project { ??? ???? ????static?class?Program ????{ ???????? ????????static?Dictionary<string,?Socket>?clientList?=?new?Dictionary<string,?Socket>(); ????????static?void?Main(string[]?args) ????????{ ???????????? ????????????Socket?serverSocket?=?new?Socket(AddressFamily.InterNetwork,?SocketType.Stream,?ProtocolType.Tcp); ????????????serverSocket.Bind(new?IPEndPoint(IPAddress.Parse("127.0.0.1"),?99)); ????????????Console.WriteLine("listening..."); ????????????serverSocket.Listen(10); ????????????while?(true) ????????????{ ????????????????Socket?socketCommu?=?serverSocket.Accept(); ????????????????clientList.Add(socketCommu.RemoteEndPoint.ToString().Split(':')[1],?socketCommu); ????????????????Console.WriteLine(socketCommu.RemoteEndPoint?+?":?connected"); ????????????????Thread?threadReceive?=?new?Thread(Receive); ????????????????threadReceive.IsBackground?=?true; ????????????????threadReceive.Start(socketCommu); ????????????????Thread?threadSend?=?new?Thread(Send); ????????????????threadSend.IsBackground?=?true; ????????????????threadSend.Start(); ????????????} ????????} static?void?Receive(object?obj) { byte[]?buffer; ????????????????Socket?socketCommu?=?obj?as?Socket; ????????????????????????while?(true) { buffer?=?new?byte[3?*?1024?*?1024]; int?r?=?socketCommu.Receive(buffer); if(r?==?0)?break; Console.WriteLine(socketCommu.RemoteEndPoint?+?":?"?+?Encoding.UTF8.GetString(buffer,?0,?r)); } ????????} ???????? static?void?Send() ????????{ ???????????? ????????????Console.WriteLine("input?client?port:"); ????????????string?port?=?Console.ReadLine(); ????????????Socket?socketCommu?=?clientList[port]; ????????????while?(true) ????????????????socketCommu.Send(Encoding.UTF8.GetBytes(Console.ReadLine())); ????????} ???????? ???????? ???????? ????} }客戶端:using?System; using?System.Collections.Generic; using?System.Linq; using?System.Text; using?System.Threading.Tasks; using?System.Net.Sockets; using?System.Net; using?System.Threading; namespace?client { ????class?Program ????{ ????????static?Socket?clientSocket; ??????? ????????static?void?Main(string[]?args) ????????{ ??????????? ????????????clientSocket?=?new?Socket(AddressFamily.InterNetwork,?SocketType.Stream,?ProtocolType.Tcp); ????clientSocket.Connect(IPAddress.Parse("127.0.0.1"),?99); ????Console.WriteLine("server?connected"); ????????????Thread?th?=?new?Thread(Send); ????th.IsBackground?=?true; ????th.Start(); ????byte[]?buffer; ????while(true) ???{ buffer?=?new?byte[3?*?1024?*?1024]; int?r?=?clientSocket.Receive(buffer); if(r?==?0)?break; Console.WriteLine(clientSocket.RemoteEndPoint?+":?"+Encoding.UTF8.GetString(buffer,?0,?r)); ???} ????????} static?void?Send() { ????while(true)? clientSocket.Send(Encoding.UTF8.GetBytes(Console.ReadLine())); } ???????? ???????? ????} }為什么輸入已經(jīng)連接的客戶端端口拋異常提示字典clientList的鍵不存在?
查看完整描述

目前暫無任何回答

  • 0 回答
  • 1 關(guān)注
  • 1357 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號