Problem with client to server connection
Ok well this will problay seem trivaial to most of you but its got my at wits ends.
i have my fire wall turned off even and i still cant get the client to connect to the server witch are bolth running on my computer.
memset( &sin, 0, sizeof sin );
sin.sin_family = AF_INET;
sin.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
sin.sin_port = htons( 21 );
if ( connect( client,(LPSOCKADDR)&sin, sizeof sin ) == SOCKET_ERROR )
{
/* could not connect to server */
MessageBox(NULL,"Error Connecting","Error",MB_OK);
}
i was just woundering if thres anything wrong with this bit of code ill post the Server code and the whole client code when i get back from work lol.. just figured id get this part up and see if it was a trival thing !
ok now that i am back and iv uploaded my server source and my client source if anyone knows winsock2 and can see a problem with how i have it setup please let me know!
I had to combine more then one tutorial to come up with this code as many tutorials are outdated.
http://www.hexdollgamez.net/server.cpp
http://www.hexdollgamez.net/server.h
http://www.hexdollgamez.net/client.cpp
http://www.hexdollgamez.net/client.h
id appreceate any help as i like would to create a mud and well i need to get this part working first!
I had to combine more then one tutorial to come up with this code as many tutorials are outdated.
http://www.hexdollgamez.net/server.cpp
http://www.hexdollgamez.net/server.h
http://www.hexdollgamez.net/client.cpp
http://www.hexdollgamez.net/client.h
id appreceate any help as i like would to create a mud and well i need to get this part working first!
1. in your server.cpp, you bind the socket to the address but you never listen on it (I tried running the server and telnet 127.0.0.1 21 didn't do anything ;) )
So, after the if ( bind(server,... (line 39, server.cpp), add this:
you can always test your server with telnet.
2. in client.cpp, you never call WSAStartup() (you should call it in StartClientNetwork(), before creating the socket).
Also, you are calling WSAAsyncSelect() first then connect(), you should call them the other way around (first call connect() then call WSAAsyncSelect()). And also, you should check for the return from WSAAsyncSelect(), if you did that you would have noticed that it returns WSANOTINITIALISED.
Hope that helps and good luck with your mud.
So, after the if ( bind(server,... (line 39, server.cpp), add this:
if ( listen(server, 0) == SOCKET_ERROR){ WSACleanup(); return false;}
you can always test your server with telnet.
2. in client.cpp, you never call WSAStartup() (you should call it in StartClientNetwork(), before creating the socket).
Also, you are calling WSAAsyncSelect() first then connect(), you should call them the other way around (first call connect() then call WSAAsyncSelect()). And also, you should check for the return from WSAAsyncSelect(), if you did that you would have noticed that it returns WSANOTINITIALISED.
Hope that helps and good luck with your mud.
Well see the thing i was trying to do was make a none blocking server so if i call listen wont it just stay there until it recives a connection ?
YAY i got it to work thanks alot, Mabye when im done my mud ill write a small tutorial on creating one for pepole intrested im a half decent programer id like to think, Not so great at the networking however im sure you notcied, Thanks kindly!
Ok just incase your still hanging around i got it to stop giving me a connection error but when i try and send some data using the send command, it seems the server dosent que the event and FD_READ never gets used do you have an idea as to why this mabye!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement