cmlabs::JSocket Class Reference

Generic Socket class. More...

#include <JSocket.h>

Inheritance diagram for cmlabs::JSocket:

Inheritance graph
[legend]
Collaboration diagram for cmlabs::JSocket:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 JSocket (JString addr, int portnumber, JString protocolname="")
 Constructor.
 JSocket (const TCPLocation &loc, JString protocolname="")
 Constructor.
 JSocket (SOCKET new_sock)
 Constructor.
virtual ~JSocket ()
Objectclone () const
bool setUpListening ()
 Bind to port.
JSocketwaitForConnection (long timeout)
 Wait for incoming connection. Returns NULL or a Socket*.
bool connectNow ()
 Tries to connect to remote Socket.
bool connectNow (const IPNumber &ip, int port)
 Under the hood connectNow().
bool disconnectNow ()
 Tries to disconnect from remote Socket, called by terminate.
bool terminate ()
 Terminates the local Socket, will auto disconnectNow.
int flush ()
int read (char *buffer, int maxcount, long timeout)
 Read a number of bytes from socket.
JString readString (int count, long timeout)
 Read a String from socket.
JString readln (long timeout)
 Read a line (ending with <CR>) from socket.
int write (JString str)
 Write a string to socket.
int write (char *ch, int len)
 Write a string to socket.
int writeln (JString str)
 Write a string and a <CR> to socket.
void setNonBlockingMode ()
void setBlockingMode ()
JString getLocalIPAddress ()
Collection getLocalIPAddresses ()
Dictionary getLocalInterfaceAddresses ()
JString getLocalHostname ()
JString getRemoteHostname ()
JString getRemoteIPAddress ()
JString getIPAddressFromName (JString name)
IPNumber getIPNumberFromName (JString name)
JString getHostnameFromIPAddress (JString ipaddr)
bool isConnected (int timeout=0)
 Is the Socket connected?
bool waitForReadability (int timeout)
 Wait timeout ms for data availability...
bool waitForWriteability (int timeout)
 Wait timeout ms for data to be written...
bool didConnectionGoThrough (int timeout)
 Is the Socket connected?
bool isListening ()
 Is the Socket connected?
bool isLastErrorRecoverable ()
 Is last error recoverable?
JString getLastErrorMessage ()
 Get the last error message.
int getLastOSErrorNumber ()
 Get the last error number, OS specific.
void osCloseSocket (SOCKET thisSocket)
 Close down the socket, OS specific.
bool isSocketValid ()
bool setSocketNotValid ()
bool createSocket ()
void dealWithSocketError (int wsaError, JString intro="")
int peekIntoStream ()
int peekIntoStream (char *buffer, int maxcount)
int readIntoBuffer ()
int readChar (char *ch)
int writeString (JString text)
int writeBuffer (char *buf, int length)
double getSendProgress ()
double getReceiveProgress ()
long getSendBufferSize ()
long getReadBufferSize ()
double * getIOCounts ()
bool resetIOCounts ()

Static Public Member Functions

static bool isIPAddressPrivate (JString addr)

Public Attributes

TCPLocation location
JString address
JString localhostName
int port
JString protocol
JString lastErrorMessage
IPNumber ipnumber
char charBuffer [BUFFERSIZE+8]
int charBufferCount
JString stringBuffer
bool connected
bool lastErrorRecoverable
bool listening
SOCKET mySocket
int currentUnsentBufferSize
int currentSentBufferSize
int currentUnreceivedBufferSize
int currentReceivedBufferSize
double ioCounts [2]
Collection localIPAddresses
JString localIPAddress
JMutex mutex
bool isTerminating


Detailed Description

Generic Socket class.

A Socket is one end of a network connection, to have communication you need a Socket in each end, connected to each other.

When you create a Socket object you provide it with an address which can be blank, a port number and a protocol type. For a listener you need the address to be blank and then ask it to listen(). For a regular connection you say connect() and it will try to connect to a listener on the remote machine.

Definition at line 132 of file JSocket.h.


Constructor & Destructor Documentation

cmlabs::JSocket::JSocket ( JString  addr,
int  portnumber,
JString  protocolname = "" 
)

Constructor.

Takes three parameters

Parameters:
addr the ip address, ignored for listeners.
portnumber the ip port, always needed.
protocolname the protocol, default = tcp.

Definition at line 69 of file JSocket.cpp.

cmlabs::JSocket::JSocket ( const TCPLocation loc,
JString  protocolname = "" 
)

Constructor.

Takes one parameters

Parameters:
loc a TCPLocation

Definition at line 97 of file JSocket.cpp.

cmlabs::JSocket::JSocket ( SOCKET  new_sock  ) 

Constructor.

Takes one parameters

Parameters:
new_sock the OS socket to base this instance on.

Definition at line 1069 of file JSocket.cpp.

cmlabs::JSocket::~JSocket (  )  [virtual]

Definition at line 125 of file JSocket.cpp.


Member Function Documentation

bool cmlabs::JSocket::isIPAddressPrivate ( JString  addr  )  [static]

Definition at line 2003 of file JSocket.cpp.

Object* cmlabs::JSocket::clone (  )  const [virtual]

Implements cmlabs::Object.

Definition at line 163 of file JSocket.h.

bool cmlabs::JSocket::setUpListening (  ) 

Bind to port.

Definition at line 1093 of file JSocket.cpp.

JSocket * cmlabs::JSocket::waitForConnection ( long  timeout  ) 

Wait for incoming connection. Returns NULL or a Socket*.

Definition at line 1168 of file JSocket.cpp.

bool cmlabs::JSocket::connectNow (  ) 

Tries to connect to remote Socket.

Definition at line 1409 of file JSocket.cpp.

bool cmlabs::JSocket::connectNow ( const IPNumber ip,
int  port 
)

Under the hood connectNow().

Definition at line 1362 of file JSocket.cpp.

bool cmlabs::JSocket::disconnectNow (  ) 

Tries to disconnect from remote Socket, called by terminate.

Definition at line 1439 of file JSocket.cpp.

bool cmlabs::JSocket::terminate (  ) 

Terminates the local Socket, will auto disconnectNow.

Definition at line 143 of file JSocket.cpp.

int cmlabs::JSocket::flush (  ) 

Definition at line 160 of file JSocket.cpp.

int cmlabs::JSocket::read ( char *  buffer,
int  maxcount,
long  timeout 
)

Read a number of bytes from socket.

Parameters:
buffer is the char* buffer
maxcount max number of bytes to read.
timeout timeout in ms

Definition at line 173 of file JSocket.cpp.

JString cmlabs::JSocket::readString ( int  count,
long  timeout 
)

Read a String from socket.

Parameters:
count number of bytes to read - no less!
timeout timeout in ms to wait for count bytes

Definition at line 256 of file JSocket.cpp.

JString cmlabs::JSocket::readln ( long  timeout  ) 

Read a line (ending with <CR>) from socket.

Parameters:
timeout timeout in ms

Definition at line 316 of file JSocket.cpp.

int cmlabs::JSocket::write ( JString  str  ) 

Write a string to socket.

Parameters:
str string to write.

Definition at line 383 of file JSocket.cpp.

int cmlabs::JSocket::write ( char *  ch,
int  len 
)

Write a string to socket.

Parameters:
ch chars to write.
len number of chars to write

Definition at line 387 of file JSocket.cpp.

int cmlabs::JSocket::writeln ( JString  str  ) 

Write a string and a <CR> to socket.

Parameters:
str string to write.

Definition at line 391 of file JSocket.cpp.

void cmlabs::JSocket::setNonBlockingMode (  ) 

Definition at line 58 of file JSocket_Linux.cpp.

void cmlabs::JSocket::setBlockingMode (  ) 

Definition at line 65 of file JSocket_Linux.cpp.

JString cmlabs::JSocket::getLocalIPAddress (  ) 

Definition at line 402 of file JSocket.cpp.

Collection cmlabs::JSocket::getLocalIPAddresses (  ) 

Definition at line 430 of file JSocket.cpp.

Dictionary cmlabs::JSocket::getLocalInterfaceAddresses (  ) 

Definition at line 603 of file JSocket.cpp.

JString cmlabs::JSocket::getLocalHostname (  ) 

Definition at line 726 of file JSocket.cpp.

JString cmlabs::JSocket::getRemoteHostname (  ) 

Definition at line 1007 of file JSocket.cpp.

JString cmlabs::JSocket::getRemoteIPAddress (  ) 

Definition at line 971 of file JSocket.cpp.

JString cmlabs::JSocket::getIPAddressFromName ( JString  name  ) 

Definition at line 1355 of file JSocket.cpp.

IPNumber cmlabs::JSocket::getIPNumberFromName ( JString  name  ) 

Definition at line 1254 of file JSocket.cpp.

JString cmlabs::JSocket::getHostnameFromIPAddress ( JString  ipaddr  ) 

Definition at line 1012 of file JSocket.cpp.

bool cmlabs::JSocket::isConnected ( int  timeout = 0  ) 

Is the Socket connected?

Definition at line 1784 of file JSocket.cpp.

bool cmlabs::JSocket::waitForReadability ( int  timeout  ) 

Wait timeout ms for data availability...

Definition at line 1921 of file JSocket.cpp.

bool cmlabs::JSocket::waitForWriteability ( int  timeout  ) 

Wait timeout ms for data to be written...

Definition at line 1963 of file JSocket.cpp.

bool cmlabs::JSocket::didConnectionGoThrough ( int  timeout  ) 

Is the Socket connected?

Definition at line 1999 of file JSocket.cpp.

bool cmlabs::JSocket::isListening (  ) 

Is the Socket connected?

Definition at line 148 of file JSocket.cpp.

bool cmlabs::JSocket::isLastErrorRecoverable (  ) 

Is last error recoverable?

Definition at line 152 of file JSocket.cpp.

JString cmlabs::JSocket::getLastErrorMessage (  ) 

Get the last error message.

Definition at line 156 of file JSocket.cpp.

int cmlabs::JSocket::getLastOSErrorNumber (  ) 

Get the last error number, OS specific.

Definition at line 118 of file JSocket_Linux.cpp.

void cmlabs::JSocket::osCloseSocket ( SOCKET  thisSocket  ) 

Close down the socket, OS specific.

Definition at line 39 of file JSocket_Linux.cpp.

bool cmlabs::JSocket::isSocketValid (  ) 

Definition at line 45 of file JSocket_Linux.cpp.

bool cmlabs::JSocket::setSocketNotValid (  ) 

Definition at line 52 of file JSocket_Linux.cpp.

bool cmlabs::JSocket::createSocket (  ) 

Definition at line 72 of file JSocket_Linux.cpp.

void cmlabs::JSocket::dealWithSocketError ( int  wsaError,
JString  intro = "" 
)

Definition at line 102 of file JSocket_Linux.cpp.

int cmlabs::JSocket::peekIntoStream (  ) 

Definition at line 1488 of file JSocket.cpp.

int cmlabs::JSocket::peekIntoStream ( char *  buffer,
int  maxcount 
)

Definition at line 1493 of file JSocket.cpp.

int cmlabs::JSocket::readIntoBuffer (  ) 

Definition at line 1533 of file JSocket.cpp.

int cmlabs::JSocket::readChar ( char *  ch  ) 

Definition at line 1449 of file JSocket.cpp.

int cmlabs::JSocket::writeString ( JString  text  ) 

Definition at line 1597 of file JSocket.cpp.

int cmlabs::JSocket::writeBuffer ( char *  buf,
int  length 
)

Definition at line 1601 of file JSocket.cpp.

double cmlabs::JSocket::getSendProgress (  ) 

Definition at line 2032 of file JSocket.cpp.

double cmlabs::JSocket::getReceiveProgress (  ) 

Definition at line 2021 of file JSocket.cpp.

long cmlabs::JSocket::getSendBufferSize (  ) 

Definition at line 136 of file JSocket.cpp.

long cmlabs::JSocket::getReadBufferSize (  ) 

Definition at line 139 of file JSocket.cpp.

double * cmlabs::JSocket::getIOCounts (  ) 

Definition at line 2045 of file JSocket.cpp.

bool cmlabs::JSocket::resetIOCounts (  ) 

Definition at line 2051 of file JSocket.cpp.


Member Data Documentation

Definition at line 239 of file JSocket.h.

Definition at line 240 of file JSocket.h.

Definition at line 241 of file JSocket.h.

Definition at line 242 of file JSocket.h.

Definition at line 243 of file JSocket.h.

Definition at line 244 of file JSocket.h.

Definition at line 250 of file JSocket.h.

char cmlabs::JSocket::charBuffer[BUFFERSIZE+8]

Definition at line 251 of file JSocket.h.

Definition at line 253 of file JSocket.h.

Definition at line 254 of file JSocket.h.

Definition at line 256 of file JSocket.h.

Definition at line 257 of file JSocket.h.

Definition at line 258 of file JSocket.h.

Definition at line 295 of file JSocket.h.

Definition at line 307 of file JSocket.h.

Definition at line 308 of file JSocket.h.

Definition at line 311 of file JSocket.h.

Definition at line 312 of file JSocket.h.

Definition at line 317 of file JSocket.h.

Definition at line 327 of file JSocket.h.

Definition at line 328 of file JSocket.h.

Definition at line 330 of file JSocket.h.

Definition at line 331 of file JSocket.h.


The documentation for this class was generated from the following files:

Generated on Tue Jul 7 16:22:50 2009 for CoreLibrary by  doxygen 1.5.6