C ++失败在SOCKET accept()方法 [英] C++ Failing at SOCKET accept() Method
问题描述
我目前正在创建一个服务器,我学会了这样的:
while(true)
{
SOCKET s = accept(s,....)
//使用连接执行某些操作
printf(connection\\\
);
}
我学会了它会坚持接受连接。
在我的程序有没有任何连接,但它得到溢出与连接??
b $ b
THX Guys i现在固定:)
很可能会立即返回错误,似乎在检查。例如。可能是因为没有正确创建等。
编辑:只是注意到您将accept相同的's',这是非常错误的。你的's'是一个一般的监听套接字,可能是由socket()创建的,由bind()绑定,并设置为listen by listen(),而accept()的返回值是另一个应该用于传输数据的套接字。 / p>
看看这个例子(只是Googling发现): http://www.cs.odu.edu/~cs476/fall03/lectures/sockets.htm
I am currently make a Server, I learned to make something like this:
while(true)
{
SOCKET s = accept(s, ....)
// do something with the connection
printf("connection\n");
}
I learned that it will stuck at accept(..) while there isnt a connection. In my Program there isnt any connection yet, but it get overflowed with connection ?? I mean my Console got spammed with "connection".
So whats wrong?
THX Guys i fixed it now :)
Most likely it returns immediately with an error which you don't seem to be checking. E.g. it may be that s wasn't properly created, etc.
Edit: just noticed that you are assigning the result of accept() to the same 's', which is terribly wrong. Your 's' is a general listening socket presumably created by socket(), bound by bind() and set to listening by listen(), whereas the return value of accept() is another socket which you should use for transfering data.
Take a look at this for example (just found by Googling): http://www.cs.odu.edu/~cs476/fall03/lectures/sockets.htm
这篇关于C ++失败在SOCKET accept()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!