• What is your GameDev Story?

Archived

This topic is now archived and is closed to further replies.

Winsock

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

Recommended Posts

Ok, I saw the new winsock tutorial up, wow, its great. But my problem is using winsock to connect to a server (asp in my case), I really have no clue and MFC is too much for me at the moment. Anyone? And, as for the code in that tut, that would be for a server running that code right, which means I''d need my own server.... right? I mean is there any free server that would support that, no right?

Share on other sites
Very quick rundown on Winsock client applications:

To connect to a server at www.myserver.com running on port 1234,
  // define hostLPHOSTENT host = gethostbyname( "www.myserver.com" );if( host == NULL ) return -1;//// create socket - internet address family, stream, TCP/IPSOCKET s = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );if( s == SOCKET_INVALID ) return -1;//// set up the internet address structureSOCKADDR_IN sockaddr;sockaddr.sin_family = AF_INET;sockaddr.sin_addr = *( (LPIN_ADDR)*host->h_addr_list );sockaddr,sin_port = htons( 1234 ); // this is the connection port//// connectint err = connect( s, (LPSOCKADDR)&sockaddr, sizeof(sockaddr) );if( err == SOCKET_ERROR ) return -1;// Ready to go!

Look at send() and recv() to see how to transfer data, and closesocket() to disconnect from the server.

Share on other sites
What do I haveto include for all those classes to work?

Share on other sites
and what kind of info can I send recieve? I mean, especially teh recieve part, how does it work?

as for send, just ints and chars and other vars, or hwatever the new lingo is?

Share on other sites
A socket is very much like a file. Anything you can write to / read from a file, you can send/receive on a socket. The only difference is you use send() and recv() instead of fwrite() and fread().

codeka.com - Just click it.

Share on other sites
but how can you recieve. I mean, ummm.....

ok, I never use fwrite/read I always use cin/out. can someone explain these to me?

Share on other sites
ignore the recieve part, but I do not know howto use fread/write, I have always used cin/out. Can someone please explain htese briefly or link me to a tutorial.

Share on other sites
Here is a useful Winsock (client)tutorial. You''ll need to include winsock2.h and add ws2_32.lib to your project.

Share on other sites
cool, great link, but it seems I''d haveto learna lot in order to be able to be able to send info to a FTP server, so i''m wondering, a programmer of 9years suggested I use ASP w/ winsock, anyone know how that would work with the ASP?

Share on other sites
quote:
Original post by Dean Harding
A socket is very much like a file. Anything you can write to / read from a file, you can send/receive on a socket. The only difference is you use send() and recv() instead of fwrite() and fread().

codeka.com - Just click it.

Actually a socket is a file descriptor. In Unix they''re represented by ints, but Winsock typedefs an unsigned int to give you a socket. Thats why sockets use file read/write operations (same goes for unix pipes).

Actually I wrote an FTP Client implementation, and there was less to it than I though. I can give you the pseudo-code if you wish.

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 14
• 46
• 22
• 27
• Forum Statistics

• Total Topics
634048
• Total Posts
3015235
×