/***********************************************************************/ /* Course: Computer Science 402a */ /* Assignment: Assignment 3 */ /* Instructor: Mark Giesbrecht */ /* Submitted by: Dan Fraser */ /* Student Number: 001219229 */ /* Due Date: Wednesday, February 16 */ /***********************************************************************/ /* StreamSocket.h - Interface for the StreamSocket wrapper class */ /***********************************************************************/ #ifndef _STREAMSOCKET_H_ #define _STREAMSOCKET_H_ //#include "Socket.h" #include #include #include #include #include #include #include #include #include class StreamSocket { public: /************************************************************************ Function Name: StreamSocket - constructor Input Parameters: n/a Output Parameters: n/a Description: creates and initalizes new StreamSocket ************************************************************************/ StreamSocket(); /************************************************************************ Function Name: send Input Parameters: data - void pointer to data length - length of data or string - C++ string to be sent optional, socket - socket to send to Output Parameters: returns standard C return from send() Description: send data to a happy socket ************************************************************************/ virtual int send(void *, int length); virtual int send(string); virtual int send(int to, void *, int length); /************************************************************************ Function Name: receive the exact opposite of send. ************************************************************************/ virtual int receive (void *, int length); virtual int receive (int from, void *, int length); /************************************************************************ Function Name: connect Input Parameters: hostname - hostname of remote machine port - port number on remote machine Output Parameters: returns returncode from C's connect() Description: connects this socket to a remote socket. ************************************************************************/ virtual int connect(string hostname, int port); /************************************************************************ Function Name: bind Input Parameters: port (optional) - request that socket be bound to port Output Parameters: port number bound Description: binds socket to port for listening ************************************************************************/ virtual int bind(int port = 0); /************************************************************************ Function Name: listen Input Parameters: qsize - integer listen queue size Output Parameters: standard C return from listen() Description: tells OS to listen to port ************************************************************************/ virtual int listen(int qsize); /************************************************************************ Function Name: accept() Input Parameters: n/a Output Parameters: returns descriptor of remote socket Description: blocks until a connection is made ************************************************************************/ virtual int accept(); /************************************************************************ Function Name: disconnect Input Parameters: socket (optional) - socket to be disconnected Output Parameters: passes return from disconnect() C call Description: disconnects a socket, this one by default ************************************************************************/ virtual int disconnect(int socket = 0); /************************************************************************ Function Name: remotehost Input Parameters: n/a Output Parameters: returns remote host dotted quad as string ***********************************************************************/ virtual string remoteHost(); /************************************************************************ Function Name: localHost Input Parameters: n/a Output Parameters: returns a local IP address as dotted quad as string ************************************************************************/ virtual string localHost(); private: int sock; struct sockaddr_in server, remote; // socket address data sturctures struct hostent *hp, *gethostbyname(); // host ent data structures }; #endif