91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

1、SocketSever服務(wù)器端代碼

2、SocketClient客戶端代碼

3、VS2019上測試通過,修改IP地址和端口號就可以直接編譯使用

資源截圖

代碼片段和文件信息

using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
using?System.Windows.Forms;
using?System.Net;
using?System.Net.Sockets;
using?System.Threading;

namespace?SocketDemo.Client
{
????public?partial?class?FrmSocketClientMain?:?Form
????{
????????public?FrmSocketClientMain()
????????{
????????????InitializeComponent();
????????}
????????//創(chuàng)建1個客戶端套接字和1個負責監(jiān)聽服務(wù)端請求的線程?
????????static?Thread?ThreadClient?=?null;
????????static?Socket?SocketClient?=?null;

????????private?void?btnConnect_Click(object?sender?EventArgs?e)
????????{
????????????IPAddress?ip?=?IPAddress.Parse(this.txtServerIP.Text);
????????????IPEndPoint?ipe?=?new?IPEndPoint(ip?Convert.ToInt32(?this.txtServerPort.Text));
????????????//定義一個套接字監(jiān)聽?
????????????SocketClient?=?new?Socket(AddressFamily.InterNetwork?SocketType.Stream?ProtocolType.Tcp);
????????????try
????????????{
????????????????//客戶端套接字連接到網(wǎng)絡(luò)節(jié)點上,用的是Connect?
????????????????SocketClient.Connect(ipe);
????????????}
????????????catch?(Exception)
????????????{
????????????????listBox1.Items.Add(DateTime.Now.ToString(“yyyy-MM-dd?HH:mm:ss:ffff“)?+?“??“?+?“連接失敗“);
????????????????return;
????????????}
????????????ThreadClient?=?new?Thread(Recv);
????????????ThreadClient.IsBackground?=?true;
????????????ThreadClient.Start();
????????}

????????//發(fā)送字符信息到服務(wù)端的方法?
????????public?static?void?ClientSendMsg(string?sendMsg)
????????{
????????????//將輸入的內(nèi)容字符串轉(zhuǎn)換為機器可以識別的字節(jié)數(shù)組???
????????????byte[]?arrClientSendMsg?=?Encoding.UTF8.GetBytes(sendMsg);
????????????//調(diào)用客戶端套接字發(fā)送字節(jié)數(shù)組???
????????????SocketClient.Send(arrClientSendMsg);
????????}
????????//接收服務(wù)端發(fā)來信息的方法??
????????public??void?Recv()
????????{
????????????//持續(xù)監(jiān)聽服務(wù)端發(fā)來的消息?
????????????while?(true)
????????????{
????????????????try
????????????????{
????????????????????//定義一個1M的內(nèi)存緩沖區(qū),用于臨時性存儲接收到的消息?
????????????????????byte[]?arrRecvmsg?=?new?byte[1024?*?1024];
????????????????????//將客戶端套接字接收到的數(shù)據(jù)存入內(nèi)存緩沖區(qū),并獲取長度?
????????????????????int?length?=?SocketClient.Receive(arrRecvmsg);
????????????????????//將套接字獲取到的字符數(shù)組轉(zhuǎn)換為人可以看懂的字符串?
????????????????????string?strRevMsg?=?Encoding.UTF8.GetString(arrRecvmsg?0?length);
????????????????????listBox1.Items.Add(DateTime.Now.ToString(“yyyy-MM-dd?HH:mm:ss:ffff“)?+?“??“?+“服務(wù)器:“?+?strRevMsg?);
????????????????}
????????????????catch?(Exception?ex)
????????????????{
????????????????????listBox1.Items.Add(DateTime.Now.ToString(“yyyy-MM-dd?HH:mm:ss:ffff“)?+?“??“?+?“遠程服務(wù)器已經(jīng)中斷連接!“?+?ex.Message?);
????????????????????break;
????????????????}
????????????}
????????}

????????private?void?btnDisConnect_Click(object?sender?EventArgs?e)
????????{
????????????if?(SocketClient?!=?null)
????????????????SocketClient.Dispose();
????????}

????????private?void?btnSend_Click(object?sender?EventArgs?e)
????????{
????????????if?(!string.IsNullOrEmpty(this.txtMsg.

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????1632??2021-05-13?14:45??SocketDemo.sln

?????文件????????187??2021-05-13?11:03??SocketClient\App.config

?????文件?????730112??2021-05-13?14:59??SocketClient\bin\Debug\SocketClient.exe

?????文件????????187??2021-05-13?11:03??SocketClient\bin\Debug\SocketClient.exe.config

?????文件??????34304??2021-05-13?14:59??SocketClient\bin\Debug\SocketClient.pdb

?????文件???????3518??2021-05-13?14:56??SocketClient\FrmSocketClientMain.cs

?????文件??????10159??2021-05-13?14:57??SocketClient\FrmSocketClientMain.Designer.cs

?????文件?????543623??2021-05-13?14:44??SocketClient\FrmSocketClientMain.resx

?????文件?????358334??2021-05-13?14:44??SocketClient\Network.ico

?????文件????????210??2021-05-13?11:03??SocketClient\obj\Debug\.NETframeworkVersion=v4.5.AssemblyAttributes.cs

?????文件???????7248??2021-05-13?14:56??SocketClient\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

?????文件?????????42??2021-05-13?14:59??SocketClient\obj\Debug\SocketClient.csproj.CoreCompileInputs.cache

?????文件????????870??2021-05-13?14:59??SocketClient\obj\Debug\SocketClient.csproj.FileListAbsolute.txt

?????文件???????1026??2021-05-13?14:59??SocketClient\obj\Debug\SocketClient.csproj.GenerateResource.cache

?????文件?????730112??2021-05-13?14:59??SocketClient\obj\Debug\SocketClient.exe

?????文件??????34304??2021-05-13?14:59??SocketClient\obj\Debug\SocketClient.pdb

?????文件?????358900??2021-05-13?14:59??SocketClient\obj\Debug\SocketDemo.Client.FrmSocketClientMain.resources

?????文件????????180??2021-05-13?14:59??SocketClient\obj\Debug\SocketDemo.Client.Properties.Resources.resources

?????文件???????3584??2021-05-13?14:56??SocketClient\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll

?????文件????????543??2021-05-13?14:58??SocketClient\Program.cs

?????文件???????1316??2021-05-13?11:03??SocketClient\Properties\AssemblyInfo.cs

?????文件???????2890??2021-05-13?14:56??SocketClient\Properties\Resources.Designer.cs

?????文件???????5612??2021-05-13?11:03??SocketClient\Properties\Resources.resx

?????文件???????1118??2021-05-13?14:56??SocketClient\Properties\Settings.Designer.cs

?????文件????????249??2021-05-13?11:03??SocketClient\Properties\Settings.settings

?????文件???????3812??2021-05-13?14:56??SocketClient\SocketClient.csproj

?????文件????????187??2021-05-13?11:01??SocketServer\App.config

?????文件????1091072??2021-05-14?16:18??SocketServer\bin\Debug\SocketServer.exe

?????文件????????187??2021-05-13?11:01??SocketServer\bin\Debug\SocketServer.exe.config

?????文件??????38400??2021-05-14?16:18??SocketServer\bin\Debug\SocketServer.pdb

............此處省略43個文件信息

評論

共有 條評論