Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error 88, socket operation on nonsocket

Status
Not open for further replies.

ezeke1

Programmer
Mar 20, 2003
41
US
Hello All,
In writing a simple server application using C, I encountered a weird bind() error. After creating a socket, my bind will fail and I receive a return error of Error 88 Socket Operation on Nonsocket. Has anyone seen this problem before or know what may be causing it? I'll paste my code below....thank you all in advance!

int main(int argc, char *argv[])
{

BeginAcceptingConnections(); // Bind server

return 0;
}

void BeginAcceptingConnections()
{
struct sockaddr_in serv_addr; // Host server address
unsigned short servport; // Local server port
int servsocket_fd; // Server socket file desc


servport = HOST_SERVER_LISTENPORT; // Assign server port
// HOST_SERVER_LISTENPORT is defined in host_ports.h

// Create socket for incoming connections
if (servsocket_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) < 0) {
printf("Served socket failed\n");
exit(1);
}

// Construct local address structure
memset(&serv_addr, 0, sizeof(serv_addr)); // Zero out structure
serv_addr.sin_family = AF_INET; // Internet address family
serv_addr.sin_addr.s_addr = inet_addr(HOST_SERVER_IP); // Any incoming interface
//serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); // Any incoming interface
serv_addr.sin_port = htons(servport); // Local port

printf("HOST SERVER IP IS : %s", HOST_SERVER_IP);
printf("\n");
printf("HOST SERVER PORT IS : %d", servport);
printf("\n");

// Bind to local address
if (bind(servsocket_fd, (struct sockaddr*) &serv_addr, sizeof(struct sockaddr_in)) < 0) {
printf("Binding failed. ERROR => %d %s\n", errno, strerror(errno));
//close(servsocket_fd);
//exit(1);
}

printf("------Server connection established------\n");

BeginListening(servsocket_fd); // Begin listening for connections


}
 
Someone else pointed out that the problem was caused by a syntax error in my socket().

just a fyi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top