Hiroshi Yamaguchi / SimpleSocket 1.0

Dependents:   SimpleSocketExamples 1.0

Embed: (wiki syntax)

« Back to documentation index

ClientSocket Class Reference

ClientSocket Class Reference

client socket class for communication endpoint More...

#include <SimpleSocket.h>

Public Member Functions

 ClientSocket (IpAddr ip, int port, float timeout=60, bool debug=false)
 creates a ClientSocket object.
 ClientSocket (char *hostname, int port, float timeout=60, bool debug=false)
 creates a ClientSocket object.
 ClientSocket (const ClientSocket &that)
 copy constructor
IpAddr getIp ()
 gets the IP address.
bool connected ()
 gets the connection status.
bool available ()
 tests if input data available or not.
int read ()
 reads a char.
int read (char *buf, int size)
 reads data into the specified buffer.
int scanf (const char *format,...)
 scans input stream according to the specified format string.
int write (char c)
 writes a char to the output stream.
int write (char *buf, int size)
 writes an array of chars to the output stream.
int printf (const char *format,...)
 prints the data to the socket output stream according to the specified format string.
void close ()
 closes the connection.
void setDebug (bool debug)
 sets debug mode.
 operator bool ()
 an operator shorthand for connected()

Friends

class ServerSocket

Detailed Description

client socket class for communication endpoint

Definition at line 159 of file SimpleSocket.h.


Constructor & Destructor Documentation

ClientSocket ( IpAddr  ip,
int  port,
float  timeout = 60,
bool  debug = false 
)

creates a ClientSocket object.

Parameters:
ipIP address of the socket
portport number of the socket
timeoutmax waiting time until connected
debugset true to display debugging information

Definition at line 33 of file ClientSocket.cpp.

ClientSocket ( char *  hostname,
int  port,
float  timeout = 60,
bool  debug = false 
)

creates a ClientSocket object.

Parameters:
hostnamedomain/host name of the socket
portport number of the socket
timeoutmax waiting time until connected
debugset true to display debugging information

Definition at line 38 of file ClientSocket.cpp.

ClientSocket ( const ClientSocket that )

copy constructor

Definition at line 44 of file ClientSocket.cpp.


Member Function Documentation

bool available (  )

tests if input data available or not.

Returns:
true if incomming data available, false otherwise

Definition at line 89 of file ClientSocket.cpp.

void close (  )

closes the connection.

Definition at line 211 of file ClientSocket.cpp.

bool connected (  )

gets the connection status.

Returns:
true if connected, false otherwise

Definition at line 79 of file ClientSocket.cpp.

IpAddr getIp (  )

gets the IP address.

Returns:
IP address of the socket

Definition at line 75 of file ClientSocket.cpp.

operator bool (  )

an operator shorthand for connected()

Definition at line 222 of file ClientSocket.cpp.

int printf ( const char *  format,
  ... 
)

prints the data to the socket output stream according to the specified format string.

Parameters:
formatprintf format string, corresponding arguments follow
Returns:
number of chars written, or -1 if failed

Definition at line 201 of file ClientSocket.cpp.

int read (  )

reads a char.

Returns:
a char from the socket input stream, or -1 if no data available

Definition at line 131 of file ClientSocket.cpp.

int read ( char *  buf,
int  size 
)

reads data into the specified buffer.

Parameters:
bufinput buffer
sizesize of the buffer
Returns:
the size of the data read

Definition at line 149 of file ClientSocket.cpp.

int scanf ( const char *  format,
  ... 
)

scans input stream according to the specified format string.

format scanf format string, corresponding arguments follow

Returns:
number of input items assigned

Definition at line 172 of file ClientSocket.cpp.

void setDebug ( bool  debug )

sets debug mode.

Parameters:
debugtrue to display debugging information

Definition at line 226 of file ClientSocket.cpp.

int write ( char  c )

writes a char to the output stream.

Parameters:
ca char to be written to the socket output stream
Returns:
positive int if succeeded, or -1 if failed

Definition at line 187 of file ClientSocket.cpp.

int write ( char *  buf,
int  size 
)

writes an array of chars to the output stream.

Parameters:
bufan array of chars to be written to the socket output stream
sizenumber of chars in the array
Returns:
number of chars written, or -1 if failed

Definition at line 191 of file ClientSocket.cpp.