Jump to content
  • Advertisement

Archived

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

Sinner_Zero

Winsock

This topic is 6166 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, 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 this post


Link to post
Share on other sites
Advertisement
Very quick rundown on Winsock client applications:

To connect to a server at www.myserver.com running on port 1234,
  
// define host

LPHOSTENT host = gethostbyname( "www.myserver.com" );
if( host == NULL ) return -1;
//

// create socket - internet address family, stream, TCP/IP

SOCKET s = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
if( s == SOCKET_INVALID ) return -1;
//

// set up the internet address structure

SOCKADDR_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

//

// connect

int 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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites

  • 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!