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

資源簡介

TCP的接收要發(fā)送功能都已經(jīng)封狀成類,大家可以盡量少的代碼就可以復(fù)用。實(shí)現(xiàn)的功能也很簡 單,只有一個(gè)接收和一個(gè)發(fā)送。代碼中注釋滿滿,大家一起研究吧。希望大家通過這個(gè)小程序 熟悉TCP實(shí)的基本過程和要求。 VS2010 C# .NET4.0下編譯通過

資源截圖

代碼片段和文件信息

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;

namespace?C_Sharp_Tcp
{
????public?partial?class?FormMain?:?Form
????{
????????TcpServer?tcpServer?=?null;
????????TcpClient?tcpClient?=?null;
????????public?FormMain()
????????{
????????????InitializeComponent();
????????}

????????private?void?FormMain_Load(object?sender?EventArgs?e)
????????{
????????????tcpServer?=?new?TcpServer();
????????????tcpServer.ReceiveEvent?+=?new?TcpServer.ReceiveHandler(myTcp_ReceiveEvent);
????????????tcpServer.StartListen(Convert.ToInt32(txtPort.Text));

????????????tcpClient?=?new?TcpClient();
????????????tcpClient.SendEvent?+=?new?TcpClient.SendHandler(tcpClient_SendEvent);
????????????btnSend.Enabled?=?tcpClient.Connect(txtIp.Text?Convert.ToInt32(txtPort.Text));
????????}

????????void?myTcp_ReceiveEvent(string?data)
????????{
????????????//必須要使用代理
????????????this.BeginInvoke(new?Action(()?=>?lstReceive.Items.Add(data)));
????????}

????????void?tcpClient_SendEvent(string?data)
????????{
????????????//必須要使用代理
????????????this.BeginInvoke(new?Action(()?=>?lstSend.Items.Add(data)));
????????}

????????private?void?btnSend_Click(object?sender?EventArgs?e)
????????{
????????????if?(tcpClient.Send(txtMsg.Text))
????????????????txtMsg.Text?=?string.Empty;
????????}

????????protected?override?void?OnClosing(CancelEventArgs?e)
????????{
????????????//通知服務(wù)器循環(huán)退出
????????????tcpClient.Send(TcpServer.ExitCode);
????????????//等待服務(wù)器處理
????????????System.Threading.Thread.Sleep(500);
????????????//斷開客戶端套接字
????????????tcpClient.DisConnect();

????????????//閉關(guān)閉服務(wù)器監(jiān)聽
????????????tcpServer.StopListen();

????????????base.OnClosing(e);
????????}
????}
}

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-05-26?18:47??C_Sharp_Tcp\
?????文件????????4093??2017-05-26?18:07??C_Sharp_Tcp\C_Sharp_Tcp.csproj
?????文件?????????911??2017-05-26?18:07??C_Sharp_Tcp\C_Sharp_Tcp.sln
?????文件???????24064??2017-05-26?18:46??C_Sharp_Tcp\C_Sharp_Tcp.suo
?????文件????????7768??2017-05-26?18:43??C_Sharp_Tcp\FormMain.Designer.cs
?????文件????????1947??2017-05-26?18:43??C_Sharp_Tcp\FormMain.cs
?????文件????????5817??2017-05-26?18:43??C_Sharp_Tcp\FormMain.resx
?????文件?????????495??2017-05-26?18:09??C_Sharp_Tcp\Program.cs
?????目錄???????????0??2017-05-26?18:07??C_Sharp_Tcp\Properties\
?????文件????????2858??2017-05-26?18:09??C_Sharp_Tcp\Properties\Resources.Designer.cs
?????文件????????5612??2010-05-30?18:21??C_Sharp_Tcp\Properties\Resources.resx
?????文件????????1107??2017-05-26?18:09??C_Sharp_Tcp\Properties\Settings.Designer.cs
?????文件?????????249??2010-05-30?18:21??C_Sharp_Tcp\Properties\Settings.settings
?????文件???????42496??2017-05-26?18:07??C_Sharp_Tcp\TCPServer.suo
?????文件????????1677??2017-05-26?18:46??C_Sharp_Tcp\TcpClient.cs
?????文件????????2879??2017-05-26?18:13??C_Sharp_Tcp\TcpServer.cs

評(píng)論

共有 條評(píng)論