Jan 10, 2013 at 9:11pm UTC
Last edited on Jan 12, 2013 at 8:58pm UTC
Jan 11, 2013 at 12:34pm UTC
Last edited on Jan 11, 2013 at 12:35pm UTC
Jan 11, 2013 at 2:57pm UTC
Thanks iHutch105 and coder777, it fixed that problem.
But now I get the same style of error from bind()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
void ServerSocket::bind()
{
if (index < 0 || index > 99) throw NetCodeException("Index out of bounds( 0-99 )" , "bind()" );
address = new INetAddress("127.0.0.1" ,2700 + index);
int r = ::bind(sock, (const struct sockaddr*) address->address, sizeof (struct sockaddr));
if (r == SOCKET_ERROR)
{
delete address;
throw SocketException(WSAGetLastError(), "bind()" );
}
bound = true ;
}
...
try
{
ServerSocket * ss = new ServerSocket(0);
ss->bind(0);
ss->listen(5);
Socket* s = ss->accept();
Packet pack;
pack.data = (byte*)"Hello wob." ;
pack.size = 10;
ss->send(s,&pack);
Packet* p = ss->recv(s);
printf("Received %s\n" ,p);
ss->close(s);
ss->stop();
delete p;
} catch (const SocketException &x)
{
print(x.what());
return ;
}
Error code:
Got error code #0 while bind()
The thing I find peculiar is that WSAGetLastError does not return anything useful.
Last edited on Jan 11, 2013 at 2:58pm UTC
Jan 11, 2013 at 4:54pm UTC
No success, INADDR_ANY
is basicly just (long )0
which I have tried..
Jan 11, 2013 at 7:07pm UTC
This
int r = ::bind(sock, (const struct sockaddr*) address->address, sizeof (struct sockaddr));
should be this
int r = ::bind(sock, (const struct sockaddr*) address->address, sizeof (struct sockaddr_in ));
I'm not sure about that address->address thing.
If you don't pass the size of the socket address record, it won't know what kind of address it is. It's an object oriented library implemented in C.
Last edited on Jan 11, 2013 at 7:08pm UTC
Jan 11, 2013 at 7:27pm UTC
Thanks for the advice, it might save me from future bugs, but it didn't fix the problem.
Last edited on Jan 12, 2013 at 3:46pm UTC
Jan 12, 2013 at 6:01pm UTC
Hi there,
You may want to try moving the thread into "general C++ programming" or "windows programming" for better luck getting an answer to your question. Just a suggestion.
All the best,
NwN
Jan 12, 2013 at 8:52pm UTC
Well thank you for the suggestion, I'll do that.