xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

資源簡介

c#基于TCP協議的Socket通信完整實例(實現多人聊天室),通過C#winform實現多人聊天,同時服務器可以向指定客戶端發送消息

資源截圖

代碼片段和文件信息

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

namespace?Client
{
????public?partial?class?MainForm?:?Form
????{
????????private?IPEndPoint?ServerInfo;
????????private?Socket?ClientSocket;
????????//信息接收緩存
????????private?Byte[]?MsgBuffer;
????????//信息發送存儲
????????private?Byte[]?MsgSend;

????????public?MainForm()
????????{
????????????InitializeComponent();
????????}

????????private?void?MainForm_Load(object?sender?EventArgs?e)
????????{
????????????//this.CmdSend.Enabled?=?false;
????????????//this.CmdExit.Enabled?=?false;
????????????//定義一個IPV4,TCP模式的Socket
????????????ClientSocket?=?new?Socket(AddressFamily.InterNetwork?SocketType.Stream?ProtocolType.Tcp);
????????????MsgBuffer?=?new?Byte[65535];
????????????MsgSend?=?new?Byte[65535];
????????????//允許子線程刷新數據
????????????CheckForIllegalCrossThreadCalls?=?false;
????????????UserName.Text?=?Environment.MachineName;
????????????ServerIP.Text?=?“127.0.0.1“;
????????}

????????private?void?CmdEnter_Click(object?sender?EventArgs?e)
????????{
????????????//服務端IP和端口信息設定這里的IP可以是127.0.0.1,可以是本機局域網IP,也可以是本機網絡IP
????????????ServerInfo?=?new?IPEndPoint(IPAddress.Parse(this.ServerIP.Text)?Convert.ToInt32(8008));

????????????try
????????????{
????????????????//客戶端連接服務端指定IP端口,Sockket
????????????????ClientSocket.Connect(ServerInfo);
????????????????//將用戶登錄信息發送至服務器,由此可以讓其他客戶端獲知
????????????????ClientSocket.Send(Encoding.Unicode.GetBytes(“用戶:?“?+?this.UserName.Text?+?“?進入系統!“));
????????????????//開始從連接的Socket異步讀取數據。接收來自服務器,其他客戶端轉發來的信息
????????????????//AsyncCallback引用在異步操作完成時調用的回調方法
????????????????ClientSocket.BeginReceive(MsgBuffer?0?MsgBuffer.Length?SocketFlags.None?new?AsyncCallback(ReceiveCallBack)?null);

????????????????this.SysMsg.Text?=?“登錄服務器成功!“;
????????????????this.CmdSend.Enabled?=?true;
????????????????this.CmdEnter.Enabled?=?false;
????????????????this.CmdExit.Enabled?=?true;
????????????}
????????????catch
????????????{
????????????????MessageBox.Show(“登錄服務器失敗,請確認服務器是否正常工作!“);
????????????}


????????}
????????private?void?ReceiveCallBack(IAsyncResult?AR)
????????{
????????????try
????????????{
????????????????//結束掛起的異步讀取,返回接收到的字節數。?AR,它存儲此異步操作的狀態信息以及所有用戶定義數據
????????????????int?REnd?=?ClientSocket.EndReceive(AR);

????????????????lock?(this.RecieveMsg)
????????????????{
????????????????????this.RecieveMsg.AppendText(Encoding.Unicode.GetString(MsgBuffer?0?REnd)?+?“\n“);
????????????????}
????????????????ClientSocket.BeginReceive(MsgBuffer?0?MsgBuffer.Length?0?new?AsyncCallback(ReceiveCallBack)?null);

????????????}
????????????catch
????????????{
????????????????MessageBox.Show(“已經與服務器斷開連接!“);
????????????????this.Close();
????????????}

????????}

????????private?void?CmdExit_Click(object?sender?EventArgs?

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-11-17?19:55??TCP.Demo\
?????目錄???????????0??2011-08-25?10:31??TCP.Demo\Client\
?????目錄???????????0??2011-08-25?10:31??TCP.Demo\Client\Client\
?????文件????????3686??2011-08-12?11:05??TCP.Demo\Client\Client\Client.csproj
?????文件????????8981??2011-08-25?10:25??TCP.Demo\Client\Client\MainForm.Designer.cs
?????文件????????4628??2011-08-25?10:29??TCP.Demo\Client\Client\MainForm.cs
?????文件????????5817??2011-08-25?10:25??TCP.Demo\Client\Client\MainForm.resx
?????文件?????????490??2011-08-12?10:58??TCP.Demo\Client\Client\Program.cs
?????目錄???????????0??2011-08-25?10:31??TCP.Demo\Client\Client\Properties\
?????文件????????1344??2011-08-12?10:53??TCP.Demo\Client\Client\Properties\AssemblyInfo.cs
?????文件????????2862??2011-08-12?10:53??TCP.Demo\Client\Client\Properties\Resources.Designer.cs
?????文件????????5612??2011-08-12?10:53??TCP.Demo\Client\Client\Properties\Resources.resx
?????文件????????1091??2011-08-12?10:53??TCP.Demo\Client\Client\Properties\Settings.Designer.cs
?????文件?????????249??2011-08-12?10:53??TCP.Demo\Client\Client\Properties\Settings.settings
?????目錄???????????0??2011-08-25?10:31??TCP.Demo\Client\Client\bin\
?????目錄???????????0??2011-08-25?10:31??TCP.Demo\Client\Client\bin\Debug\
?????文件???????12800??2011-08-25?10:29??TCP.Demo\Client\Client\bin\Debug\Client.exe
?????文件???????26112??2011-08-25?10:29??TCP.Demo\Client\Client\bin\Debug\Client.pdb
?????文件???????11600??2011-08-25?10:30??TCP.Demo\Client\Client\bin\Debug\Client.vshost.exe
?????文件?????????490??2010-03-17?22:39??TCP.Demo\Client\Client\bin\Debug\Client.vshost.exe.manifest
?????目錄???????????0??2018-11-17?19:56??TCP.Demo\Client\Client\bin\Release\
?????目錄???????????0??2011-08-25?10:31??TCP.Demo\Client\Client\obj\
?????目錄???????????0??2011-08-25?10:31??TCP.Demo\Client\Client\obj\x86\
?????目錄???????????0??2011-08-25?10:31??TCP.Demo\Client\Client\obj\x86\Debug\
?????文件?????????180??2011-08-25?10:27??TCP.Demo\Client\Client\obj\x86\Debug\Client.MainForm.resources
?????文件?????????180??2011-08-24?23:25??TCP.Demo\Client\Client\obj\x86\Debug\Client.Properties.Resources.resources
?????文件????????1253??2011-08-25?10:30??TCP.Demo\Client\Client\obj\x86\Debug\Client.csproj.FileListAbsolute.txt
?????文件???????12800??2011-08-25?10:29??TCP.Demo\Client\Client\obj\x86\Debug\Client.exe
?????文件???????26112??2011-08-25?10:29??TCP.Demo\Client\Client\obj\x86\Debug\Client.pdb
?????文件????????4440??2011-08-24?22:58??TCP.Demo\Client\Client\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件????????6181??2011-08-25?10:29??TCP.Demo\Client\Client\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
............此處省略40個文件信息

評論

共有 條評論