[英]send(), returns Winsock Error 10038
Problem: 问题:
Illustration: 插图:
acceptedSocket = accept (server, (sockaddr *)&sin, &len);
Illustration: - in thread function 插图: -螺纹功能
//omitted
SOCKET RemoteSocket = (SOCKET) client;
//omitted
send (RemoteSocket, stringToSpend, strlen(stringToSpend), 0)
Suggestions: 建议:
accept() returns you a handle to a new connection-specific socket. accept()返回一个新的特定于连接的套接字的句柄。 for server code it's 2+ sockets involved: one is in listen state you are calling accept() for and second is one returned from accept() - it's an incoming connection socket.
对于服务器代码,它涉及2个以上的套接字:一个处于侦听状态,您正在为其调用accept(),第二个是从accept()返回的一个-这是一个传入的连接套接字。 Following accept() can return socket for second incoming connection etc. if accept() returns 0 it's not an incoming connection - it's an error.
跟随accept()可以为第二次传入连接返回套接字,等等。如果accept()返回0,则它不是传入连接-这是一个错误。
Isn't the problem in the line 这不是问题所在吗
acceptedSocket = accept (server, (sockaddr *)&sin, &len) == INVALID_SOCKET)
You make acceptedSocket
the result of the comparison, but you should store the actual socket returned from accept somehow: 您使
acceptedSocket
作为比较的结果,但是您应该以某种方式存储从accept返回的实际套接字:
acceptedSocket = accept (server, (sockaddr *)&sin, &len);
isOK= acceptedSocket!=INVALID_SOCKET;
Although I'm a bit confused by the unbalanced parentheses in your post, so I may be wrong 尽管我对您的帖子中括号不平衡有些困惑,所以我可能是错的
Hmm, seems like your send
is executing too fast before the accept
happened. 嗯,好像您的
send
在accept
发生之前执行得太快了。 So the socket used in send is not valid at the point send is executed. 因此,在执行send时,send中使用的套接字无效。 One of the obnoxious feature of multithreading.
多线程的令人讨厌的功能之一。 You need to wait for an event at the
send
thread and fire an event when an accept occurs 您需要在
send
线程上等待事件,并在接受时触发事件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.