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?
Very quick rundown on Winsock client applications:
To connect to a server at www.myserver.com running on port 1234,
Look at send() and recv() to see how to transfer data, and closesocket() to disconnect from the server.
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.
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?
as for send, just ints and chars and other vars, or hwatever the new lingo is?
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.
codeka.com - Just click it.
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?
ok, I never use fwrite/read I always use cin/out. can someone explain these to me?
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.
Here is a useful Winsock (client)tutorial. You''ll need to include winsock2.h and add ws2_32.lib to your project.
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?
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement