guess you missed the "fixed the bind"
now what ment, what is my next step!
working on the accept() part.
will post code in a few!
//-----update-----//
Code:
#include <winsock2.h>
#include <Windows.h>
#include <stdio.h>
#define PORT 8888
int main(void)
{
WSADATA wsaData;
int socket_desc;
struct sockaddr_in server_addr, client_addr;
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = INADDR_ANY;
server_addr.sin_port = htons(PORT);
if (WSAStartup(MAKEWORD(2,0), &wsaData) != 0)
{
fprintf(stderr,"Server: WSAStartup failed.\n", WSAGetLastError());
}
else
{
printf("Server: WSAStartup Success.\n");
}
socket_desc = socket(AF_INET , SOCK_STREAM , 0);
if (socket_desc == -1)
{
fprintf(stderr,"Server: Could not create socket.\n", WSAGetLastError());
}
else
{
printf("Server: Socket Created.\n");
}
int retcode = bind(socket_desc, (struct sockaddr*)&server_addr, sizeof(server_addr));
if (retcode < 0)
{
fprintf(stderr,"Server: bind() failed with error %d\n", WSAGetLastError());
}
else
{
printf("Server: Socket bound.\n");
}
if (listen(socket_desc,5) == SOCKET_ERROR)
{
fprintf(stderr,"Server: listen() failed with error %d\n", WSAGetLastError());
}
else
{
printf("Server: listen() is OK.\n");
}
printf("Server: I'm listening and waiting connection on port %d\n\n", PORT);
while(1)
{
int fromlen =sizeof(client_addr);
if (accept(socket_desc, (struct sockaddr*)&client_addr, &fromlen) < 0)
{
fprintf(stderr,"Server: accept() error %d\n", WSAGetLastError());
}
else
{
printf("Server: accept() is OK.\n");
printf("Server: accepted connection from %s, port %d\n", inet_ntoa(client_addr.sin_addr), htons(client_addr.sin_port));
}
}
WSACleanup();
return 0;
}
OK, have a few errors, mostly "infiniate and code not reachable" no prob to me, because I am not done yet!
but lost to "Result of comparison is constant."
now really don't know what to do next!!!
do I keep the loop where it is, and put a receive in the loop, or do I unloop the listen, and make a loop with receive?
and also might need help on the receive part!