问题描述
在使用TCPClient / Listener时,我遇到了错误"连接请求是在已连接的套接字192.168.1.8:8001上进行的"。经过进一步检查,我发现它是Winsock错误10045,操作不受支持。
While working with the TCPClient/Listener, I ran into the error "A connect request was made on an already connected socket 192.168.1.8:8001". Upon further inspection I have found that it is the Winsock Error 10045, Operation Not Supported.
我在MSDN论坛和其他地方看了很多不同的帖子,但一直无法找到什么我做错了。 TCPListener工作正常(据我所知,由于无法连接)。
$
$
我的代码对于TCPClient如下:
I have looked upon many different Posts in the MSDN forums and elsewhere and have been unable to find out what i am doing wrong. The TCPListener is working Perfectly (As far as i have been able to see, due to being unable to connect).
My code for the TCPClient is as follows:
IPEndPoint LPoint = new IPEndPoint(IPAddress.Parse("192.168.1.8"), 8001);
TcpClient LClient = new TcpClient("192.168.1.8", 8001);
LClient.Connect(LPoint); ;
if (LClient.Connected)
{
listBox1.Items.Add("Connected on 192.168.1.8:8001");
using (Stream stream = LClient.GetStream())
{
string str = "Test";
ASCIIEncoding asen = new ASCIIEncoding();
byte[] ba = asen.GetBytes(str);
stream.Write(ba, 0, ba.Length);
}
}
推荐答案
这篇关于TCPClient Winsock错误10045的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!