资源简介
C#实现Socket编程 (异步通讯,解决Tcp粘包)
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Text;
#region 命名空间
using System.Threading;
using SocketCommon;
using System.Net;
#endregion
namespace ClientConsole
{
class Program
{
static void Main(string[] args)
{
#region 测试消息发送并匹配协议
TcpClient client = new TcpClient();
client.AsynConnect();
Console.WriteLine(“下面将连续发送3条测试消息...“);
Console.ReadKey();
MessageProtocol msgPro;
for (int i = 0; i < 3; i++)
{
msgPro = new MessageProtocol(“我是liger_zql“);
Console.WriteLine(“第{0}条:{1}“ i + 1 msgPro.MessageInfo.Content);
client.AsynSend(msgPro);
}
#endregion
#region 发送文件测试
Console.ReadKey();
Console.WriteLine(“推送文件...“);
msgPro = new MessageProtocol()
{
MessageType = MessageType.file
RequestFile = new RequestFile()
{
Mode = RequestMode.send
Fileobject = new Fileobject()
{
FileName = “KKSetup_3602.exe“
}
}
};
UdpServer udpServer = new UdpServer(msgPro.RequestFile);
client.AsynSend(msgPro);
#endregion
#region 接收文件测试
Console.ReadKey();
Console.WriteLine(“接收文件...“);
msgPro = new MessageProtocol()
{
MessageType = MessageType.file
RequestFile = new RequestFile()
{
Mode = RequestMode.recive
Fileobject = new Fileobject()
{
FileName = “20090901093002.rar“
}
}
};
udpServer = new UdpServer(msgPro.RequestFile);
client.AsynSend(msgPro);
#endregion
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2013-05-14 22:31 SocketProQuests\
目录 0 2013-05-14 22:31 SocketProQuests\ClientConsole\
目录 0 2013-05-14 22:31 SocketProQuests\ClientConsole\bin\
目录 0 2013-05-14 22:31 SocketProQuests\ClientConsole\bin\Debug\
文件 8192 2013-05-14 22:27 SocketProQuests\ClientConsole\bin\Debug\ClientConsole.exe
文件 17920 2013-05-14 22:27 SocketProQuests\ClientConsole\bin\Debug\ClientConsole.pdb
文件 11608 2013-05-14 13:31 SocketProQuests\ClientConsole\bin\Debug\ClientConsole.vshost.exe
文件 490 2010-03-17 22:39 SocketProQuests\ClientConsole\bin\Debug\ClientConsole.vshost.exe.manifest
文件 17920 2013-05-14 22:27 SocketProQuests\ClientConsole\bin\Debug\SocketCommon.dll
文件 58880 2013-05-14 22:27 SocketProQuests\ClientConsole\bin\Debug\SocketCommon.pdb
目录 0 2013-05-08 11:37 SocketProQuests\ClientConsole\bin\Release\
文件 2499 2013-05-14 22:26 SocketProQuests\ClientConsole\ClientConsole.csproj
目录 0 2013-04-30 15:46 SocketProQuests\ClientConsole\obj\
目录 0 2013-04-30 15:46 SocketProQuests\ClientConsole\obj\x86\
目录 0 2013-05-14 22:31 SocketProQuests\ClientConsole\obj\x86\Debug\
文件 2733 2013-05-14 22:27 SocketProQuests\ClientConsole\obj\x86\Debug\ClientConsole.csproj.FileListAbsolute.txt
文件 8192 2013-05-14 22:27 SocketProQuests\ClientConsole\obj\x86\Debug\ClientConsole.exe
文件 17920 2013-05-14 22:27 SocketProQuests\ClientConsole\obj\x86\Debug\ClientConsole.pdb
文件 5191 2013-05-14 22:27 SocketProQuests\ClientConsole\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
目录 0 2013-04-30 15:46 SocketProQuests\ClientConsole\obj\x86\Debug\TempPE\
文件 2205 2013-05-14 20:44 SocketProQuests\ClientConsole\Program.cs
目录 0 2013-04-30 15:46 SocketProQuests\ClientConsole\Properties\
文件 1376 2013-04-29 23:56 SocketProQuests\ClientConsole\Properties\AssemblyInfo.cs
文件 1502 2013-05-14 20:44 SocketProQuests\ClientConsole\TcpClient.cs
文件 2543 2013-05-14 13:56 SocketProQuests\ClientConsole\UdpServer.cs
目录 0 2013-05-14 22:31 SocketProQuests\ServerConsole\
目录 0 2013-05-14 22:31 SocketProQuests\ServerConsole\bin\
目录 0 2013-05-14 22:31 SocketProQuests\ServerConsole\bin\Debug\
文件 8192 2013-05-14 22:27 SocketProQuests\ServerConsole\bin\Debug\ServerConsole.exe
文件 17920 2013-05-14 22:27 SocketProQuests\ServerConsole\bin\Debug\ServerConsole.pdb
文件 11608 2013-05-14 20:50 SocketProQuests\ServerConsole\bin\Debug\ServerConsole.vshost.exe
............此处省略47个文件信息
- 上一篇:基于c#的手机短信收发程序
- 下一篇:C#制作科学计算器课程设计(源程序)
评论
共有 条评论