Jump to content
  • Advertisement
Sign in to follow this  
Jouei

Problem with client to server connection

This topic is 4218 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 !

Share this post


Link to post
Share on other sites
Advertisement
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!

Share this post


Link to post
Share on other sites
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:


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.

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Yep ok all fixed, So just incase anyone else reads this and is intrested in a mud tutorial i will be making one shortly after im done the game!

Thanks to everyone that has helped me with coding issues in the past few weeks !

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!