Programming With Sockets

Programming With Sockets - Programming With Sockets Client...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Programming With Sockets Client Side int cs =socket(PF_INET, SOCK_STREAM, proto) Connect(cs, addr, sizeof(addr)) Write(cs, buf, len) Read(cs, buf, len); Close(cs) See: http://www.cs.purdue.edu/homes/cs354/lab5-http-server/client.cpp
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Programming With Sockets Server Side int masterSocket = socket(PF_INET, SOCK_STREAM, 0); int err = setsockopt(masterSocket, SOL_SOCKET, SO_REUSEADDR, (char *) &optval, sizeof( int ) ); int error = bind( masterSocket, (struct sockaddr *)&serverIPAddress, sizeof(serverIPAddress) ); error = listen( masterSocket, QueueLength); while ( 1 ) { int slaveSocket = accept( masterSocket, (struct sockaddr*)&clientIPAddress, (socklen_t*)&alen);
Background image of page 2
Client for Daytime Server //------------------------------------------------------------------------ // Program: client // // Purpose: allocate a socket, connect to a server, and print all output // // Syntax: client host port // // host - name of a computer on which server is executing // port - protocol port number server is using // //------------------------------------------------------------------------ #define closesocket close #include <sys/types.h>
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Client for Daytime Server void printUsage() { printf( "Usage: client <host> <port> <name>\n"); printf( "\n"); printf( " host: host where the server is running.\n"); printf( " port: port that the server is using.\n"); printf( "\n"); printf( "Examples:\n"); printf( "\n"); printf( " client localhost 422422\n"); printf( " client lore 1345\n");
Background image of page 4
Client for Daytime Server int main(int argc, char **argv) { // Check command-line argument for protocol port and extract
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/30/2012 for the course CS 252 taught by Professor Gustavorodriguez during the Fall '11 term at Purdue University-West Lafayette.

Page1 / 20

Programming With Sockets - Programming With Sockets Client...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online