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

  • 大小: 1.85MB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2023-09-01
  • 語言: C#
  • 標簽: c#??socket??同時??

資源簡介

vs2005編寫,c#使用一個socket同時發送字符串和文件

資源截圖

代碼片段和文件信息

using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;
//fhf
using?System.Net;
using?System.Net.Sockets;
using?System.IO;
using?System.Threading;

namespace?Receiver
{
????public?partial?class?FormReceiver?:?Form
????{
????????Socket?socket;
????????Int32?port?=?13000;
????????string?ip?=?“127.0.0.1“;
????????Thread?mythread;
????????delegate?void?setTextbox(string?strConn);
????????setTextbox?_setTextbox?=?null;

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


????????private?void?FormReceiver_Load(object?sender?EventArgs?e)
????????{
????????????try
????????????{
????????????????_setTextbox?=?new?setTextbox(this.DispText);
????????????????mythread?=?new?Thread(new?ThreadStart(BeginListen));
????????????????mythread.Start();
????????????}
????????????catch
????????????{
????????????????socket.Close();
????????????????mythread.Abort();
????????????}
????????}

????????private?void?FormReceiver_FormClosing(object?sender?FormClosingEventArgs?e)
????????{
????????????System.Environment.Exit(0);?
????????}

????????private?void?DispText(string?str)
????????{
????????????textBox1.Text?=?str;
????????}

????????private?void?BeginListen1()
????????{
????????????IPAddress?ipAddress?=?IPAddress.Parse(ip);
????????????socket?=?new?Socket(AddressFamily.InterNetwork?SocketType.Stream?ProtocolType.Tcp);
????????????IPEndPoint?iep?=?new?IPEndPoint(ipAddress?port);
????????????byte[]?byteMessage?=?new?byte[1048576];
????????????socket.Bind(iep);
????????????while?(true)
????????????{
????????????????Socket?newSocket?=?null;
????????????????try
????????????????{
????????????????????socket.Listen(10);
????????????????????newSocket?=?socket.Accept();
????????????????????int?bytes?=?0;
????????????????????int?datanum?=?0;?
????????????????????string?s?=?““;
????????????????????while?(true)
????????????????????{
????????????????????????bytes?=?newSocket.Receive(byteMessage?byteMessage.Length?0);
????????????????????????datanum?=?BitConverter.ToInt32(byteMessage?0);???//從buffer中的前4個字節讀出count?
????????????????????????if?(bytes?<=?0)
????????????????????????????break;
????????????????????????s?+=?Encoding.Unicode.GetString(byteMessage4bytes-4);
????????????????????}???????????????????
????????????????????string?sTime?=?DateTime.Now.ToShortTimeString();
????????????????????string?msg?=?sTime?+?“?“?+?“Message?from?“?+?newSocket.RemoteEndPoint.ToString()?+?“?:“;
????????????????????//字符串
????????????????????msg?+=?s;
????????????????????//在文本框內顯示
????????????????????this.Invoke(_setTextbox?msg);
????????????????}
????????????????catch(Exception?e)
????????????????{
????????????????????newSocket.Close();
????????????????????MessageBox.Show(e.ToString());
????????????????}
????????????}
????????}

????????private?void?Begin

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2012-08-09?14:26??SocketTest\
?????目錄???????????0??2012-08-12?00:39??SocketTest\Receiver\
?????目錄???????????0??2012-08-09?22:34??SocketTest\Receiver\bin\
?????目錄???????????0??2012-08-12?00:35??SocketTest\Receiver\bin\Debug\
?????文件??????951755??2012-08-12?00:41??SocketTest\Receiver\bin\Debug\1.jpg
?????文件???????24576??2012-08-12?00:39??SocketTest\Receiver\bin\Debug\Receiver.exe
?????文件???????28160??2012-08-12?00:39??SocketTest\Receiver\bin\Debug\Receiver.pdb
?????文件????????5632??2005-11-11?22:25??SocketTest\Receiver\bin\Debug\Receiver.vshost.exe
?????文件????????7396??2012-08-12?00:39??SocketTest\Receiver\FormReceiver.cs
?????文件????????2941??2012-08-12?00:38??SocketTest\Receiver\FormReceiver.Designer.cs
?????文件????????5814??2012-08-12?00:38??SocketTest\Receiver\FormReceiver.resx
?????目錄???????????0??2012-08-09?22:36??SocketTest\Receiver\obj\
?????目錄???????????0??2012-08-12?00:39??SocketTest\Receiver\obj\Debug\
?????文件?????????849??2012-08-12?00:38??SocketTest\Receiver\obj\Debug\Receiver.csproj.GenerateResource.Cache
?????文件???????24576??2012-08-12?00:39??SocketTest\Receiver\obj\Debug\Receiver.exe
?????文件?????????180??2012-08-12?00:38??SocketTest\Receiver\obj\Debug\Receiver.FormReceiver.resources
?????文件???????28160??2012-08-12?00:39??SocketTest\Receiver\obj\Debug\Receiver.pdb
?????文件?????????180??2012-08-09?22:36??SocketTest\Receiver\obj\Debug\Receiver.Properties.Resources.resources
?????目錄???????????0??2012-08-09?22:34??SocketTest\Receiver\obj\Debug\Refactor\
?????目錄???????????0??2012-08-10?00:37??SocketTest\Receiver\obj\Debug\TempPE\
?????文件????????4608??2012-08-10?00:37??SocketTest\Receiver\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll
?????文件?????????554??2012-08-12?00:41??SocketTest\Receiver\obj\Receiver.csproj.FileListAbsolute.txt
?????文件?????????474??2012-08-09?22:34??SocketTest\Receiver\Program.cs
?????目錄???????????0??2012-08-09?14:26??SocketTest\Receiver\Properties\
?????文件????????1182??2012-08-09?14:26??SocketTest\Receiver\Properties\AssemblyInfo.cs
?????文件????????2840??2012-08-10?00:37??SocketTest\Receiver\Properties\Resources.Designer.cs
?????文件????????5612??2012-08-09?14:26??SocketTest\Receiver\Properties\Resources.resx
?????文件????????1106??2012-08-10?00:37??SocketTest\Receiver\Properties\Settings.Designer.cs
?????文件?????????249??2012-08-09?14:26??SocketTest\Receiver\Properties\Settings.settings
?????文件????????3295??2012-08-10?00:54??SocketTest\Receiver\Receiver.csproj
?????目錄???????????0??2012-08-12?00:41??SocketTest\Sender\
............此處省略31個文件信息

評論

共有 條評論