The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MPSocketIO Class Reference

#include <io.h>

Inheritance diagram for MPSocketIO:

Inheritance graph
[legend]
Collaboration diagram for MPSocketIO:

Collaboration graph
[legend]
List of all members.

Public Member Functions

int connectServer ()
void disconnectServer ()
int isConnect ()
 MPSocketIO (char _hostName[], int _hostPort, int _isConvert=FALSE)
char readByte ()
char readChar ()
double readDouble ()
float readFloat ()
int readFull (char bur[], int numRead)
int readInt ()
long readLong ()
void write (const double &d)
void write (const float &f)
void write (const char *s)
void write (const char &ch)
void write (const long &l)
void write (const int &i)
void writeByte (const char &b)
virtual ~MPSocketIO ()

Private Member Functions

int readConvert (char byte[], int numRead)
void writeConvert (char byte[], int numWrite)

Private Attributes

int _isConnect
MPSocketIO::DOUBLE_DATE double_data
MPSocketIO::FLOAT_DATA float_data
char hostName [40]
int hostPort
MPSocketIO::INT_DATA int_data
int isConvert
MPSocketIO::LONG_DATA long_data

Constructor & Destructor Documentation

MPSocketIO char  _hostName[],
int  _hostPort,
int  _isConvert = FALSE
 

Definition at line 24 of file socketio.cpp.

References _isConnect, hostName, hostPort, and isConvert.

00025 {
00026         //hostName = new char[strlen(_hostName)+1];
00027         strcpy(hostName,_hostName);
00028         hostPort = _hostPort;
00029         isConvert = _isConvert;
00030         _isConnect = FALSE;
00031 }

~MPSocketIO  )  [virtual]
 

Definition at line 35 of file socketio.cpp.

References disconnectServer().

00036 {
00037         disconnectServer();
00038 }

Here is the call graph for this function:


Member Function Documentation

BOOL connectServer  ) 
 

Definition at line 49 of file socketio.cpp.

References _isConnect, BOOL, clientSock, hostName, hostPort, and isConnect().

Referenced by CommThread::CommThread(), and CommThread::Process().

00050 {
00051         if((clientSock = socket(AF_INET,SOCK_STREAM,0)) < 0 ) { _isConnect = FALSE; return FALSE; }
00052         
00053         sockaddr_in cin;
00054         cin.sin_addr.s_addr = inet_addr(hostName);
00055         cin.sin_family = AF_INET;
00056         cin.sin_port= htons(hostPort);
00057         
00058         if(connect(clientSock,(struct sockaddr*)&(cin),sizeof(struct sockaddr)) < 0) {
00059                 closesocket(clientSock);
00060                 clientSock = -1;
00061                 _isConnect = FALSE;
00062         }
00063         else {
00064                 _isConnect = TRUE;
00065         }
00066         return isConnect();
00067 }

Here is the call graph for this function:

void disconnectServer  ) 
 

Definition at line 71 of file socketio.cpp.

References _isConnect, clientSock, and isConnect().

Referenced by CommThread::Process(), CommThread::~CommThread(), and ~MPSocketIO().

00072 {
00073         if(isConnect()) closesocket(clientSock);
00074         _isConnect = FALSE;
00075         clientSock = -1;
00076 }

Here is the call graph for this function:

BOOL isConnect  ) 
 

Definition at line 42 of file socketio.cpp.

References BOOL.

Referenced by connectServer(), disconnectServer(), CommThread::Process(), readConvert(), readFull(), write(), and writeByte().

00043 {
00044         return _isConnect;
00045 }

char readByte  ) 
 

Definition at line 175 of file socketio.cpp.

References readFull().

00176 {
00177         char ch;
00178         readFull(&ch,1);
00179         return ch;
00180 }

Here is the call graph for this function:

char readChar  ) 
 

int readConvert char  byte[],
int  numRead
[private]
 

Definition at line 232 of file socketio.cpp.

References clientSock, i, and isConnect().

Referenced by readDouble(), readFloat(), readInt(), and readLong().

00233 {
00234         int i , readbyte;
00235         if(isConnect()) {
00236                 if(sizeof(byte) < numRead) return -1;
00237                 for(i=numRead-1;i>=0;i--)
00238                 {
00239                         readbyte = recv(clientSock,&byte[i],1,0);
00240                         if(readbyte < 0) return -1;
00241                 }
00242                 return numRead;
00243         }
00244         return -1;
00245 }

Here is the call graph for this function:

double readDouble  ) 
 

Definition at line 220 of file socketio.cpp.

References MPSocketIO::DOUBLE_DATE::byte, MPSocketIO::DOUBLE_DATE::data, double_data, readConvert(), and readFull().

00221 {
00222         if(isConvert) {
00223                 readConvert(double_data.byte,8);
00224         } else {
00225                 readFull(double_data.byte,8);
00226         }
00227         return double_data.data;
00228 }

Here is the call graph for this function:

float readFloat  ) 
 

Definition at line 208 of file socketio.cpp.

References MPSocketIO::FLOAT_DATA::byte, MPSocketIO::FLOAT_DATA::data, float_data, readConvert(), and readFull().

00209 {
00210         if(isConvert) {
00211                 readConvert(float_data.byte,4);
00212         } else {
00213                 readFull(float_data.byte,4);
00214         }
00215         return float_data.data;
00216 }

Here is the call graph for this function:

int readFull char  bur[],
int  numRead
 

Definition at line 249 of file socketio.cpp.

References clientSock, i, and isConnect().

Referenced by readByte(), readDouble(), readFloat(), readInt(), and readLong().

00250 {
00251         int i , readbyte;
00252         if(isConnect()) {
00253                 if(sizeof(byte) < numRead) return -1;
00254                 for(i=0;i<numRead;i++)
00255                 {
00256                         readbyte = recv(clientSock,&byte[i],1,0);
00257                         if(readbyte < 0) { return -1; }
00258                 }
00259                 return numRead;
00260         }
00261         return -1;
00262 }

Here is the call graph for this function:

int readInt  ) 
 

Definition at line 184 of file socketio.cpp.

References MPSocketIO::INT_DATA::byte, MPSocketIO::INT_DATA::data, int_data, readConvert(), and readFull().

00185 {
00186         if(isConvert) {
00187                 readConvert(int_data.byte,4);
00188         } else {
00189                 readFull(int_data.byte,4);
00190         }
00191         return int_data.data;
00192 }

Here is the call graph for this function:

long readLong  ) 
 

Definition at line 196 of file socketio.cpp.

References MPSocketIO::LONG_DATA::byte, MPSocketIO::LONG_DATA::data, long_data, readConvert(), and readFull().

00197 {
00198         if(isConvert) {
00199                 readConvert(long_data.byte,8);
00200         } else {
00201                 readFull(long_data.byte,8);
00202         }
00203         return long_data.data;
00204 }

Here is the call graph for this function:

void write const double &  d  )  [virtual]
 

Implements MPIO.

Definition at line 161 of file socketio.cpp.

References MPSocketIO::DOUBLE_DATE::byte, clientSock, MPSocketIO::DOUBLE_DATE::data, double_data, isConnect(), VERIFY, and writeConvert().

00162 {
00163         if(isConnect()) {
00164                 double_data.data = d;
00165                 if(isConvert) {
00166                         writeConvert(double_data.byte,8);
00167                 } else {
00168                         VERIFY(send(clientSock,double_data.byte,8,0));
00169                 }
00170         }
00171 }

Here is the call graph for this function:

void write const float &  f  ) 
 

Definition at line 146 of file socketio.cpp.

References MPSocketIO::FLOAT_DATA::byte, clientSock, MPSocketIO::FLOAT_DATA::data, float_data, isConnect(), VERIFY, and writeConvert().

00147 {
00148         
00149         if(isConnect()) {
00150                 float_data.data = f;
00151                 if(isConvert) {
00152                         writeConvert(float_data.byte,4);
00153                 } else {
00154                         VERIFY(send(clientSock,float_data.byte,4,0));
00155                 }
00156         }
00157 }

Here is the call graph for this function:

void write const char *  s  ) 
 

Definition at line 137 of file socketio.cpp.

References clientSock, s, and VERIFY.

00138 {
00139         if(clientSock>0) {
00140                 VERIFY(send(clientSock,s,strlen(s),0));
00141         }
00142 }

void write const char &  ch  )  [virtual]
 

Implements MPIO.

Definition at line 128 of file socketio.cpp.

References clientSock, isConnect(), and VERIFY.

00129 {
00130         if(isConnect()) {
00131                 VERIFY(send(clientSock,&ch,1,0));
00132         }
00133 }

Here is the call graph for this function:

void write const long &  l  ) 
 

Definition at line 114 of file socketio.cpp.

References MPSocketIO::LONG_DATA::byte, clientSock, MPSocketIO::LONG_DATA::data, isConnect(), long_data, VERIFY, and writeConvert().

00115 {
00116         if(isConnect()) {
00117                 long_data.data = l;
00118                 if(isConvert) {
00119                         writeConvert(long_data.byte,8);
00120                 } else {
00121                         VERIFY(send(clientSock,long_data.byte,8,0));
00122                 }
00123         }
00124 }

Here is the call graph for this function:

void write const int &  i  )  [virtual]
 

Implements MPIO.

Definition at line 100 of file socketio.cpp.

References MPSocketIO::INT_DATA::byte, clientSock, MPSocketIO::INT_DATA::data, int_data, isConnect(), VERIFY, and writeConvert().

00101 {
00102         if(isConnect()) {
00103                 int_data.data = i;
00104                 if(isConvert) {
00105                         writeConvert(int_data.byte,4);
00106                 } else {
00107                         VERIFY(send(clientSock,int_data.byte,4,0));
00108                 }
00109         }
00110 }

Here is the call graph for this function:

void writeByte const char &  b  ) 
 

Definition at line 91 of file socketio.cpp.

References clientSock, isConnect(), and VERIFY.

00092 {
00093         if(isConnect()) {
00094                 VERIFY(send(clientSock,&b,1,0));
00095         }
00096 }

Here is the call graph for this function:

void writeConvert char  byte[],
int  numWrite
[private]
 

Definition at line 80 of file socketio.cpp.

References clientSock, i, and VERIFY.

Referenced by write().

00081 {
00082         if(sizeof(byte) < numByte) return;
00083         for(int i=numByte-1;i>0;i--)
00084         {
00085                 VERIFY(send(clientSock,&byte[i],1,0));
00086         }
00087 }


Member Data Documentation

int _isConnect [private]
 

Definition at line 53 of file io.h.

Referenced by connectServer(), disconnectServer(), and MPSocketIO().

union MPSocketIO::DOUBLE_DATE double_data [private]
 

Referenced by readDouble(), and write().

union MPSocketIO::FLOAT_DATA float_data [private]
 

Referenced by readFloat(), and write().

char hostName[40] [private]
 

Definition at line 57 of file io.h.

Referenced by connectServer(), and MPSocketIO().

int hostPort [private]
 

Definition at line 58 of file io.h.

Referenced by connectServer(), and MPSocketIO().

union MPSocketIO::INT_DATA int_data [private]
 

Referenced by readInt(), and write().

int isConvert [private]
 

Definition at line 54 of file io.h.

Referenced by MPSocketIO().

union MPSocketIO::LONG_DATA long_data [private]
 

Referenced by readLong(), and write().


The documentation for this class was generated from the following files:
Generated on Mon Nov 8 17:08:40 2004 for MPT by  doxygen 1.3.9.1