-
March 19th, 2013, 08:44 AM
#46
Re: getting a binding error in server program
i assumed the code from the MSDN website would be right.
ok its set to true now
it is still displaying the error for setsockopt and now it is also displaying the error message from this code:
Code:
if(listen(m_serversocket,0) < 0)
{
CString text;
text.Format(_T("ERROR listening in the server socket: %d"), WSAGetLastError()); //---error---//
AfxMessageBox(text);
exit(1);
}
error is 10045
-
March 19th, 2013, 08:52 AM
#47
Re: getting a binding error in server program
Well, it is already one step forward!
But why don't you want to find the meaning adn desription of this error? Don't you have MSDN? Or are you banned by Google?
BTW, this error means:
WSAEOPNOTSUPP (10045)
Operation not supported.
The attempted operation is not supported for the type of object referenced. Usually this occurs when a socket descriptor to a socket that cannot support this operation, for example, trying to accept a connection on a datagram socket.
For the listen function there is some additional info:
The referenced socket is not of a type that supports the listen operation.
Victor Nijegorodov
-
March 20th, 2013, 04:27 AM
#48
Re: getting a binding error in server program
ok so the error i get with listen is 10045 which is:
Operation not supported. The attempted operation is not supported for the type of object referenced. Usually this occurs when a socket descriptor to a socket that cannot support this operation is trying to accept a connection on a datagram socket.
i don't know how to solve this problem. description of the error doesn't help
-
March 20th, 2013, 04:35 AM
#49
Re: getting a binding error in server program
You got this WSAEOPNOTSUPP (10045) trying to call function listen, so the error description in this case is much shorter:
The referenced socket is not of a type that supports the listen operation.
It means that you did something was wrong between socket creation and calling listen.
The easiest way to find out what is wrong is to compare your code with some working example (from MSDN or other sites) for listening socket.
Victor Nijegorodov
-
March 20th, 2013, 05:07 AM
#50
Re: getting a binding error in server program
i have changed so much code so i started again.
here is the current code:
Code:
WSADATA wsaData;
SOCKET ListeningSocket, NewConnection;
SOCKADDR_IN ServerAddr;
int Port = 7171;
char recvbuff[1024];
int i, nlen;
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0)
{
CString text;
text.Format(_T("ERROR WSAStartup failed: %d"), WSAGetLastError());
AfxMessageBox(text);
exit (1);
}
//ListeningSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
ListeningSocket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (ListeningSocket == INVALID_SOCKET)
{
CString text;
text.Format(_T("ERROR at socket, error code: %d"), WSAGetLastError());
AfxMessageBox(text);
WSACleanup();
exit (1);
}
ServerAddr.sin_family = AF_INET;
ServerAddr.sin_port = htons(Port);
ServerAddr.sin_addr.s_addr = htonl(INADDR_BROADCAST);
if (bind(ListeningSocket, (SOCKADDR *)&ServerAddr, sizeof(ServerAddr)) == SOCKET_ERROR)
{
CString text;
text.Format(_T("ERROR bind failed, Error code: %d"), WSAGetLastError());
AfxMessageBox(text);
closesocket(ListeningSocket);
WSACleanup();
exit (1);
}
if (listen(ListeningSocket, 5) == SOCKET_ERROR)
{
CString text;
text.Format(_T("ERROR listen: Error listening on socket: %d"), WSAGetLastError());
AfxMessageBox(text);
closesocket(ListeningSocket);
WSACleanup();
exit (1);
}
while(1)
{
NewConnection = SOCKET_ERROR;
while(NewConnection == SOCKET_ERROR)
{
NewConnection = accept(ListeningSocket, NULL, NULL);
//getsockname(ListeningSocket, (SOCKADDR *)&ServerAddr, (int *)sizeof(ServerAddr));
memset(&ServerAddr, 0, sizeof(ServerAddr));
nlen = sizeof(ServerAddr);
int ret = sendto(ListeningSocket, recvbuff, strlen(recvbuff), 0, (sockaddr*)&ServerAddr, nlen);
if(ret < 0)
{
CString text;
text.Format(_T("ERROR Error broadcasting to the clients: %d"), WSAGetLastError());
AfxMessageBox(text);
}
//getpeername(NewConnection, (SOCKADDR *)&SenderInfo, &nlen);
}
}
if( shutdown(NewConnection, SD_SEND) != 0)
printf("\n\nServer: Well, there is something wrong with the shutdown. The error code: %ld\n", WSAGetLastError());
CString text;
text.Format(_T("ERROR Something wrong with shutdown, error code: %d"), WSAGetLastError());
AfxMessageBox(text);
SetTimer(0x01, 100, NULL);
}
now when i run it the error message "ERROR bind failed, Error code: 10049" displays
that error means
Cannot assign requested address.
The requested address is not valid in its context. This normally results from an attempt to bind to an address that is not valid for the local computer. This can also result from connect, sendto, WSAConnect, WSAJoinLeaf, or WSASendTo when the remote address or port is not valid for a remote computer (for example, address or port 0).
Last edited by beginner91; March 20th, 2013 at 05:09 AM.
-
March 20th, 2013, 05:15 AM
#51
Re: getting a binding error in server program
Didn't you find some working example of socket server application?
Victor Nijegorodov
-
March 20th, 2013, 05:20 AM
#52
Re: getting a binding error in server program
not one that uses broadcast. its very difficult to find. if you could link any examples that would be great
-
March 20th, 2013, 05:32 AM
#53
Re: getting a binding error in server program
Why do you use INADDR_BROADCAST instead of INADDR_ANY for your server socket?
Victor Nijegorodov
-
March 20th, 2013, 05:38 AM
#54
Re: getting a binding error in server program
i was told to use it. its a requirement
-
March 20th, 2013, 05:47 AM
#55
Re: getting a binding error in server program
Originally Posted by beginner91
i was told to use it. its a requirement
The first "requirement" for you is reading the documentation!
Understand?
If you read the documentation about INADDR_BROADCAST you'd know that it is used to send a broadcast (see http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx)
To receive the broadcasts socket uses INADDR_ANY (see the http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx)
Last edited by VictorN; March 20th, 2013 at 05:53 AM.
Victor Nijegorodov
-
March 20th, 2013, 05:49 AM
#56
Re: getting a binding error in server program
sorry those links don't work for me
-
March 20th, 2013, 05:52 AM
#57
Re: getting a binding error in server program
but i understand. so INADDR_ANY is used in the server and INADDR_BROADCAST is used in the client
-
March 20th, 2013, 05:53 AM
#58
Re: getting a binding error in server program
Originally Posted by beginner91
sorry those links don't work for me
Sorry! My fault...
I've edited links.
Victor Nijegorodov
-
March 20th, 2013, 05:58 AM
#59
Re: getting a binding error in server program
ok so i changed it to INADDR_ANY but i'm still getting the same error with listen
-
March 20th, 2013, 06:08 AM
#60
Re: getting a binding error in server program
Originally Posted by beginner91
ok so i changed it to INADDR_ANY but i'm still getting the same error with listen
with listen or with bind?
Victor Nijegorodov
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|