guit  0.1
 All Classes Functions Variables Typedefs Enumerations Friends
Public Types | Public Member Functions | Protected Attributes | List of all members
guit::GSocket Class Reference

Guit Socket; can either be a Server or a Client depending on it is started. More...

Inheritance diagram for guit::GSocket:
guit::GObject

Public Types

enum  Mode
 Server Mode.
 
enum  Status
 Socket Status. More...
 

Public Member Functions

Mode mode () const
 Returns socket mode (ie server or client, see enum Mode).
 
GIntstatus ()
 Returns connexion status (see enum Status).
 
bool startAsServer (int port)
 Starts the GSocket as a Server socket. More...
 
bool startAsClient (GString const &hostname, int port)
 Starts the GSocket as a Client socket. More...
 
void disconnect ()
 Disconnects the socket.
 
GSocketChanneloperator[] (GString const &name)
 Returns a channel of communication that can be bound to a mutable Property. More...
 
void setSendBack (bool state)
 Specifies whether data is sent back while receiving data. More...
 
virtual void error (GString const &funname, GString const &message) const
 Prints an error message. More...
 
void operator delete (void *)
 delete does nothing, see GObject class.
 
void forgetSmartPointers ()
 Forgets all smart pointers pointing this object. More...
 
unsigned int useCount () const
 Returns the numbers of smart pointers referencing the object.
 
virtual void removeNotifiers (void *obj)
 [Implementation] Notifies this object that it must no longer refer obj.
 
template<class Subclass >
Subclass * to ()
 Class conversions.
 
void ignoreSmartPointers ()
 Checks/sets whether this object can be auto-deleted by smart pointers. More...
 

Protected Attributes

int maxattempts_ {50}
 the socket is disconnected if it receives nothing more than this amount of times.
 

Detailed Description

Guit Socket; can either be a Server or a Client depending on it is started.

After creating the GSocket, startAsServer() starts it as a server and startAsClient() as a client. A GSocket can manage an abritary set of GSocketChannel(s). Each of them is treated as a separate communication channel, and can be bound with a mutable Property (GVarProp).

Note
GSocket rely on IPV4.

Member Enumeration Documentation

Socket Status.

  • Invalid: invalid socket or wrong socket type
  • CannotReach: can't connect (Client), can't bind (Server)
  • UnknownHost: can't find host

Member Function Documentation

bool guit::GSocket::startAsServer ( int  port)

Starts the GSocket as a Server socket.

Returns true if the server socket could be started (check status() in case of an error).

bool guit::GSocket::startAsClient ( GString const &  hostname,
int  port 
)

Starts the GSocket as a Client socket.

Returns true if the client socket could be started (check status() in case of an error).

GSocketChannel & guit::GSocket::operator[] ( GString const &  name)

Returns a channel of communication that can be bound to a mutable Property.

mysocket["chan"] returns the channel named "chan". Data sent to this channel will be received by the channel with the same name on the other side, and vice-versa. The name must be an ASCII string without spaces nor special characters.

mysocket["*"] is a special channel that sends/receives all data unformatted. Other channels prefix data by "_name_:"

Callbacks can be added to each channel, and channels can be bound with mutable properties; see GSocketChannel for details.

void guit::GSocket::setSendBack ( bool  state)
inline

Specifies whether data is sent back while receiving data.

Useful for avoiding useless data exchanges, especially when props are synced on both sides. When props are synced (or if both sides have callbacks) changing a updates b that updates a. If a has not been changed in the meantime everything is fine, otherwise this may cause jitter or infinite loops.

void guit::GObject::error ( GString const &  funname,
GString const &  message 
) const
virtualinherited

Prints an error message.

See Also
GApp::onError() to change error management.
void guit::GObject::ignoreSmartPointers ( )
inlineinherited

Checks/sets whether this object can be auto-deleted by smart pointers.

ignoreSmartPointers() has a permanent effect, contrary to forgetSmartPointers(). Objects not created by calling new are never auto-deleted by smart pointers.

void guit::GObject::forgetSmartPointers ( )
inlineinherited

Forgets all smart pointers pointing this object.

The smart pointers that are currently pointing to the object won't auto-delete it. forgetSmartPointers() has a temporary effect, contrary to ignoreSmartPointers().


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