資源簡介
提供了服務(wù)器和客戶端連接、通信和文件傳輸
代碼片段和文件信息
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?_2222222
{
????public?partial?class?frmClient?:?Form
????{
????????public?frmClient()
????????{
????????????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?(ipint.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();
????????}
????????void?RecMsg()
????????{
????????????while?(true)
????????????{
????????????????//?定義一個(gè)2M的緩存區(qū);
????????????????byte[]?arrMsgRec?=?new?byte[1024?*?1024?*?2];
????????????????//?將接受到的數(shù)據(jù)存入到輸入??arrMsgRec中;
????????????????int?length?=?-1;
????????????????try
????????????????{
????????????????????length?=?sockClient.Receive(arrMsgRec);?//?接收數(shù)據(jù),并返回?cái)?shù)據(jù)的長度;
????????????????}
????????????????catch?(SocketException?se)
????????????????{
????????????????????ShowMsg(“異常;“?+?se.Message);
????????????????????return;
????????????????}
????????????????catch?(Exception?e)
????????????????{
????????????????????ShowMsg(“異常:“+e.Message);
????????????????????return;
????????????????}
????????????????if?(arrMsgRec[0]?==?0)?//?表示接收到的是消息數(shù)據(jù);
????????????????{
????????????????????string?strMsg?=?System.Text.Encoding.UTF8.GetString(arrMsgRec?1?length-1);//?將接受到的字節(jié)數(shù)據(jù)轉(zhuǎn)化成字符串;
????????????????????ShowMsg(strMsg);
????????????????}
????????????????if?(arrMsgRec[0]?==?1)?//?表示接收到的是文件數(shù)據(jù);
????????????????{
???????????????????
????????????????????try
????????????????????{
????????????????????????SaveFileDialog?sfd?=?new?SaveFileDialog();
????????????????????????if?(sfd.ShowDialog(this)?==?System.Windows.Forms.DialogResult.OK)
????????????????????????{//?在上邊的?sfd.ShowDialog()?的括號里邊一定要加上?this?否則就不會彈出?另存為?的對話框,而彈出的是本類的其他窗口,,這個(gè)一定要注意!!!【解釋:加了this的sfd.ShowDialog(this),“另存為”窗口的指針才能被SaveFileDialog的對象調(diào)用,若不加thisSaveFileDialog?的對象調(diào)用的是本類的其他窗口了,當(dāng)然不彈出“另存為”窗口。】
????????????????????????????string?fileSavePath?=?sfd.FileName;//?獲得文件保存的路徑;
???
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2012-07-12?08:00??TCP?通信(數(shù)據(jù)、文件的傳輸)\
?????目錄???????????0??2020-08-26?19:32??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\
?????目錄???????????0??2020-08-19?16:20??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\.vs\
?????目錄???????????0??2020-08-19?16:20??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\.vs\2222222\
?????目錄???????????0??2020-08-19?16:20??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\.vs\2222222\v16\
?????文件???????53248??2020-09-06?19:10??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\.vs\2222222\v16\.suo
?????文件????????3872??2012-07-11?16:40??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\2222222.csproj
?????文件????????1071??2020-08-19?16:20??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\2222222.sln
?????目錄???????????0??2012-07-12?07:59??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\bin\
?????目錄???????????0??2012-07-12?07:59??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\bin\Debug\
?????文件?????4103168??2020-08-26?19:33??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\bin\Debug\2222222.exe
?????文件???????30208??2020-08-26?19:33??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\bin\Debug\2222222.pdb
?????文件???????11600??2012-07-11?19:31??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\bin\Debug\2222222.vshost.exe
?????文件?????????490??2010-03-17?22:39??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\bin\Debug\2222222.vshost.exe.manifest
?????文件????????7253??2020-08-26?19:32??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\Form1.cs
?????文件????????9250??2020-08-26?19:32??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\Form1.Designer.cs
?????文件????????6020??2020-08-26?19:32??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\Form1.resx
?????目錄???????????0??2012-07-12?07:59??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\obj\
?????目錄???????????0??2012-07-12?07:59??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\obj\x86\
?????目錄???????????0??2020-08-26?19:33??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\obj\x86\Debug\
?????文件?????????238??2020-08-19?15:27??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\obj\x86\Debug\.NETfr
?????文件??????????42??2020-08-19?15:27??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\obj\x86\Debug\2222222.csproj.CoreCompileInputs.cache
?????文件????????2475??2020-08-19?15:27??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\obj\x86\Debug\2222222.csproj.FileListAbsolute.txt
?????文件????????1101??2020-08-26?19:33??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\obj\x86\Debug\2222222.csproj.GenerateResource.cache
?????文件???????32226??2020-08-19?15:27??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\obj\x86\Debug\2222222.csprojAssemblyReference.cache
?????文件?????4103168??2020-08-26?19:33??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\obj\x86\Debug\2222222.exe
?????文件???????30208??2020-08-26?19:33??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\obj\x86\Debug\2222222.pdb
?????文件????????5157??2020-08-26?19:32??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件????????7632??2020-08-19?15:27??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????1112??2012-07-11?19:28??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\obj\x86\Debug\GenerateResource.read.1.tlog
?????文件????????1108??2012-07-11?19:28??TCP?通信(數(shù)據(jù)、文件的傳輸)\客戶端\obj\x86\Debug\GenerateResource.write.1.tlog
............此處省略54個(gè)文件信息
- 上一篇:wpf開發(fā)教程
- 下一篇:智能機(jī)柜嵌入式電源上位機(jī)軟件
評論
共有 條評論