class AsyncProgram
{
static Thread thead = null;
static Thread theadclient = null;
static int port = 12345;
static Socket server = null;
static Socket client = null;
static int buffersize = 40960000;
static void Main()
{
thead = new Thread(new ThreadStart(() => {
IPEndPoint netPoint = new IPEndPoint(IPAddress.Any,port);
server = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
server.Bind(netPoint);
server.Listen(10);
theadclient.Start();
while (true)
{
server.BeginAccept(new AsyncCallback(AcceptCallBack),server);
}
}));
thead.Start();
theadclient = new Thread(new ThreadStart(() => {
IPEndPoint netpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"),port);
client = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
client.BeginConnect(netpoint, new AsyncCallback(ConnectCallBack), client);
}));
}
static void AcceptCallBack(IAsyncResult ar)
{
Socket serve = ar.AsyncState as Socket;
serve.EndAccept(ar);
}
static void sendSata(Socket client)
{
byte[] buffers = new byte[buffersize];
FileStream file = new FileStream(@"E:\temp\iTunes64Setup.exe", FileMode.Open);
int readCount = file.Read(buffers, 0, buffersize);
client.BeginSend(buffers, 0, readCount, 0, new AsyncCallback(SendCallBack), client);
while (readCount > 0)
{
client.BeginSend(buffers, 0, readCount, 0, new AsyncCallback(SendCallBack), client);
}
file.Close();
client.Disconnect(false);
client.Close();
}
static void ConnectCallBack(IAsyncResult ar)
{
Socket client = ar.AsyncState as Socket;
client.EndConnect(ar);
sendSata(client);
}
static void SendCallBack(IAsyncResult ar)
{
Socket client = ar.AsyncState as Socket;
client.EndSend(ar);
}
}
Socket异步传输远程主机强迫关闭了一个现有的链接
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
0条回答
悬赏问题
- ¥15 c程序不知道为什么得不到结果
- ¥40 复杂的限制性的商函数处理
- ¥15 程序不包含适用于入口点的静态Main方法
- ¥15 素材场景中光线烘焙后灯光失效
- ¥15 请教一下各位,为什么我这个没有实现模拟点击
- ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
- ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
- ¥20 有关区间dp的问题求解
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置