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!
[b/
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
}
[/b]
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!
[b/
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
}
[/b]