All pastes #231713 Raw Edit

c_socket.h

public cpp v1 · immutable
#231713 ·published 2006-10-31 23:50 UTC
rendered paste body
/* socket class */#ifndef _C_SOCKET_#define _C_SOCKET_#include <iostream>#include <string>#include <fcntl.h> //close,#include <unistd.h> //sleep,#include <ctype.h> //isdigit#include <stdlib.h> //atoi#include <errno.h> //strerror,errno#include <sys/select.h> //selecttypedef struct sockaddr_in SOCKADDR_IN;#ifdef WIN32#include <winsock.h>#include <windows.h>#define sleep(x) Sleep((x) * 1000)#define socketError WSAGetLastError()#else#define closesocket(c) close(c)#include <netinet/in.h> //sockaddr_in,inet_addr,#include <sys/types.h> //socket,#include <sys/socket.h> //socket,inet_addr,send,recv,#include <arpa/inet.h> //inet_addr,#include <sys/types.h> //send,recv,#include <netdb.h> //gethostbyname,#define socketerror errno#endifusing namespace std;class c_socket{  private:	int			m_size;	int			m_sock;	char			recvBuffer[2048];	SOCKADDR_IN	m_sin;	string		m_sockError;	void			setSockError();  public:	c_socket();	~c_socket();	bool			init();	bool			setAddress(char *address);	void			setPort(unsigned short int port);	bool			setPort(char *buffer);	bool			connection();	bool			send(string buffer);	bool			recv();	void			close();	string		getSockError();	int			getSize();	char*		getRecvBuffer;};#endif