資源簡介
C#TCP通信,通過IP地址,TCP協議實現了數據的發送與接收,并且實現了文件的傳輸。
代碼片段和文件信息
using?System;
using?System.Text;
using?System.Windows.Forms;
using?System.Net;
using?System.Net.Sockets;
using?SendDataClassLibrary;
namespace?SendDataTCP
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????private?void?butExit_Click(object?sender?EventArgs?e)
????????{
?????????????this.Close()?;????????
????????}
????????
????????private?void?butSendData_Click(object?sender?EventArgs?e)
????????{
????????????IPAddress?serverIP;
????????????if?(txtServerIP.Text.Length?==0?){MessageBox.Show?(“服務器IP地址不能為空!““錯誤“);?return?;}
????????????try
????????????{
????????????????serverIP?=?IPAddress.Parse(txtServerIP.Text);
????????????}
????????????catch
????????????{
????????????????MessageBox.Show(“請輸入正確的服務器IP地址!“?“錯誤“);?return;
????????????}
????????????try
????????????{
????????????????txtServerPort.Text?=?int.Parse(txtServerPort.Text).ToString();
????????????????if?(int.Parse(txtServerPort.Text)?<=?0)?{?MessageBox.Show(“服務器端口設置錯誤!“?“錯誤“);?return;?}
????????????}
????????????catch
????????????{
????????????????
????????????}
????????????try
????????????{
????????????????SendDataClass?tcpSendData?=?new?SendDataClass();
????????????????tcpSendData.SendData(txtServerIP.Text?txtServerPort.Text?txtData.Text);
????????????????label4.Text?=?“Sent?successfully!“;?
????????????}
????????????catch
????????????{?
????????????????MessageBox.Show(“發送失敗!“+“\r\n\r\n“+“無法連接遠程服務器,請查看設置或與系統管理員聯系!“?“錯誤“);?return;
????????????}
????????}
????????private?void?txtData_TextChanged(object?sender?EventArgs?e)
????????{
????????????label4.Text?=?““;
????????}
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
????????}?
?????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????5632??2011-08-17?10:49??C#TCP通信\SendDataTCP\SendDataTCP\bin\Debug\RemotingClassLibrary.dll
?????文件??????13824??2011-08-17?10:49??C#TCP通信\SendDataTCP\SendDataTCP\bin\Debug\RemotingClassLibrary.pdb
?????文件???????5632??2011-08-17?10:52??C#TCP通信\SendDataTCP\SendDataTCP\bin\Debug\SendDataClassLibrary.dll
?????文件??????13824??2011-08-17?10:52??C#TCP通信\SendDataTCP\SendDataTCP\bin\Debug\SendDataClassLibrary.pdb
?????文件???????1636??2013-11-08?15:44??C#TCP通信\SendDataTCP\SendDataTCP\bin\Debug\SendDataTCP.application
?????文件??????11264??2013-11-08?15:44??C#TCP通信\SendDataTCP\SendDataTCP\bin\Debug\SendDataTCP.exe
?????文件???????4950??2013-11-08?15:44??C#TCP通信\SendDataTCP\SendDataTCP\bin\Debug\SendDataTCP.exe.manifest
?????文件??????30208??2013-11-08?15:44??C#TCP通信\SendDataTCP\SendDataTCP\bin\Debug\SendDataTCP.pdb
?????文件???????1636??2013-11-08?15:44??C#TCP通信\SendDataTCP\SendDataTCP\bin\Debug\SendDataTCP.vshost.application
?????文件??????11608??2013-11-08?15:45??C#TCP通信\SendDataTCP\SendDataTCP\bin\Debug\SendDataTCP.vshost.exe
?????文件???????4950??2013-11-08?15:44??C#TCP通信\SendDataTCP\SendDataTCP\bin\Debug\SendDataTCP.vshost.exe.manifest
?????文件???????1959??2011-08-19?10:08??C#TCP通信\SendDataTCP\SendDataTCP\Form1.cs
?????文件??????10269??2011-08-19?10:08??C#TCP通信\SendDataTCP\SendDataTCP\Form1.Designer.cs
?????文件???????5814??2011-08-19?10:08??C#TCP通信\SendDataTCP\SendDataTCP\Form1.resx
?????文件???????6404??2013-11-08?15:44??C#TCP通信\SendDataTCP\SendDataTCP\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????482??2013-11-08?15:44??C#TCP通信\SendDataTCP\SendDataTCP\obj\Debug\GenerateResource-ResGen.read.1.tlog
?????文件????????746??2013-11-08?15:44??C#TCP通信\SendDataTCP\SendDataTCP\obj\Debug\GenerateResource-ResGen.write.1.tlog
?????文件???????6868??2013-11-08?15:43??C#TCP通信\SendDataTCP\SendDataTCP\obj\Debug\ResolveAssemblyReference.cache
?????文件???????1636??2013-11-08?15:44??C#TCP通信\SendDataTCP\SendDataTCP\obj\Debug\SendDataTCP.application
?????文件???????4171??2013-11-08?15:45??C#TCP通信\SendDataTCP\SendDataTCP\obj\Debug\SendDataTCP.csproj.FileListAbsolute.txt
?????文件????????847??2011-08-19?10:08??C#TCP通信\SendDataTCP\SendDataTCP\obj\Debug\SendDataTCP.csproj.GenerateResource.Cache
?????文件??????11264??2013-11-08?15:44??C#TCP通信\SendDataTCP\SendDataTCP\obj\Debug\SendDataTCP.exe
?????文件???????4950??2013-11-08?15:44??C#TCP通信\SendDataTCP\SendDataTCP\obj\Debug\SendDataTCP.exe.manifest
?????文件????????180??2013-11-08?15:44??C#TCP通信\SendDataTCP\SendDataTCP\obj\Debug\SendDataTCP.Form1.resources
?????文件??????30208??2013-11-08?15:44??C#TCP通信\SendDataTCP\SendDataTCP\obj\Debug\SendDataTCP.pdb
?????文件????????180??2013-11-08?15:44??C#TCP通信\SendDataTCP\SendDataTCP\obj\Debug\SendDataTCP.Properties.Resources.resources
?????文件???????1111??2013-11-08?15:44??C#TCP通信\SendDataTCP\SendDataTCP\obj\Debug\SendDataTCP.TrustInfo.xm
?????文件???????4608??2013-11-08?15:43??C#TCP通信\SendDataTCP\SendDataTCP\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll
?????文件????????492??2011-02-09?11:05??C#TCP通信\SendDataTCP\SendDataTCP\Program.cs
?????文件???????1471??2011-06-24?11:15??C#TCP通信\SendDataTCP\SendDataTCP\Properties\app.manifest
............此處省略30個文件信息
評論
共有 條評論