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

  • 大小: 37KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2021-05-23
  • 語(yǔ)言: C#
  • 標(biāo)簽: tcp??c#??

資源簡(jiǎn)介

本代碼基于c#語(yǔ)言實(shí)現(xiàn)tcp雙工通信,分為tcp客戶端和tcp服務(wù)器端兩部分,內(nèi)含可執(zhí)行文件。

資源截圖

代碼片段和文件信息

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;
using?System.Threading;
using?System.IO;?

namespace?tcp客戶端
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????????TextBox.CheckForIllegalCrossThreadCalls?=?false;??
????????}
????????Thread?threadClient?=?null;?//?創(chuàng)建用于接收服務(wù)端消息的?線程;???
????????Socket?sockClient?=?null;

????????private?void?btnConnect_Click(object?sender?EventArgs?e)
????????{
????????????IPAddress?ip?=?IPAddress.Parse(txtIp.Text.Trim());
????????????IPEndPoint?endPoint?=?new?IPEndPoint(ip?int.Parse(txtPort.Text.Trim()));
????????????sockClient?=?new?Socket(AddressFamily.InterNetwork?SocketType.Stream?ProtocolType.Tcp);
????????????try
????????????{
????????????????ShowMsg(“與服務(wù)器連接中……“);
????????????????sockClient.Connect(endPoint);

????????????}
????????????catch?(SocketException?se)
????????????{
????????????????MessageBox.Show(se.Message);
????????????????return;
????????????????//this.Close();???
????????????}
????????????ShowMsg(“與服務(wù)器連接成功!!!“);
????????????threadClient?=?new?Thread(RecMsg);
????????????threadClient.IsBackground?=?true;
????????????threadClient.Start();??

????????}
????????public?delegate?void?DeleUpdateTextbox(string?dataRe);
????????void?RecMsg()
????????{
????????????DeleUpdateTextbox?deleupdatetextbox?=?new?DeleUpdateTextbox(UpdateTextbox);
????????????byte[]?arrMsgRec?=?new?byte[1024?*?1024?*?512];
????????????while?(true)
????????????{
????????????????//?定義一個(gè)2M的緩存區(qū);???
????????????????
????????????????//?將接受到的數(shù)據(jù)存入到輸入??arrMsgRec中;???
????????????????int?length?=?-1;
????????????????try
????????????????{
????????????????????length?=?sockClient.Receive(arrMsgRec);?//?接收數(shù)據(jù),并返回?cái)?shù)據(jù)的長(zhǎng)度;???
????????????????????arrMsgRec[length]?=?0;
????????????????}
????????????????catch?(SocketException?se)
????????????????{
????????????????????ShowMsg(“異常;“?+?se.Message);
????????????????????return;
????????????????}
????????????????catch?(Exception?e)
????????????????{
????????????????????ShowMsg(“異常:“?+?e.Message);
????????????????????return;
????????????????}
????????????????if?(arrMsgRec[0]?==?0x30)?//?表示接收到的是消息數(shù)據(jù);???
????????????????{
????????????????????string?strMsg;?//System.Text.Encoding.Default.GetString(arrMsgRec?1?length?-?1);//?將接受到的字節(jié)數(shù)據(jù)轉(zhuǎn)化成字符串;???
????????????????????//ShowMsg(strMsg);
????????????????????strMsg?=?System.Text.Encoding.UTF8.GetString(arrMsgRec?1?length?-?1);
????????????????????strMsg?=?“他說(shuō):\r\n“?+?strMsg;

????????????????????ShowMsg(strMsg);

????????????????}
????????????????if?(arrMsgRec[0]?==?0x31)?//?表示接收到的是文件數(shù)據(jù);???
????????????????{

????????????????????try
????????????????????{
????????????????????????SaveFileDialog?sfd?=?new?SaveFileDialog();

??

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-04-20?20:24??tcp通信\
?????目錄???????????0??2018-05-01?20:31??tcp通信\tcp服務(wù)器\
?????文件???????11206??2018-04-27?22:09??tcp通信\tcp服務(wù)器\Form1.cs
?????文件????????8731??2018-04-27?22:09??tcp通信\tcp服務(wù)器\Form1.Designer.cs
?????文件????????5817??2018-04-27?22:09??tcp通信\tcp服務(wù)器\Form1.resx
?????文件?????????484??2018-04-17?22:27??tcp通信\tcp服務(wù)器\Program.cs
?????文件???????14336??2018-04-27?22:09??tcp通信\tcp服務(wù)器\tcp.exe
?????文件?????????851??2018-04-20?20:22??tcp通信\tcp服務(wù)器\tcp.sln
?????文件???????24576??2018-04-27?22:09??tcp通信\tcp服務(wù)器\tcp.suo
?????目錄???????????0??2018-05-01?20:31??tcp通信\tcp客戶端\
?????文件????????7897??2018-04-20?20:21??tcp通信\tcp客戶端\Form1.cs
?????文件????????8829??2018-04-20?20:21??tcp通信\tcp客戶端\Form1.Designer.cs
?????文件????????5817??2018-04-20?20:21??tcp通信\tcp客戶端\Form1.resx
?????文件?????????493??2018-04-17?22:40??tcp通信\tcp客戶端\Program.cs
?????文件???????13824??2018-04-27?22:04??tcp通信\tcp客戶端\tcp客戶端.exe
?????文件?????????878??2018-04-20?20:22??tcp通信\tcp客戶端\tcp客戶端.sln
?????文件???????24576??2018-04-27?22:09??tcp通信\tcp客戶端\tcp客戶端.suo

評(píng)論

共有 條評(píng)論