CSAD
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | List of all members
csad::NetConnection Class Reference

NetConnection - network connection. More...

Public Types

enum  Mode { NC_TCP, NC_UDP, NC_RAW }
 socket mode More...
 

Public Member Functions

_FORCEINLINE NetConnection (char *)
 create connection
 
_FORCEINLINE NetConnectionaccept (char *)
 recive connection and create new NetConnection.
 
_FORCEINLINE unsigned _int32 addr ()
 return connection or last recv data addres.
 
_FORCEINLINE bool close ()
 Close socket.
 
_FORCEINLINE bool connect ()
 Connect.
 
_FORCEINLINE bool open ()
 Open socket.
 
_FORCEINLINE _int32 port ()
 return connection port.
 
_FORCEINLINE int read (void *data, unsigned int size)
 recive data
 
_FORCEINLINE void setAddr (char a, char b, char c, char d)
 set connection addres.
 
_FORCEINLINE void setMode (unsigned int mode)
 set connection mode
 
_FORCEINLINE void setPort (_int32 port)
 set port connection, or for open listening
 
_FORCEINLINE int write (void *data, unsigned int size)
 send data
 

Detailed Description

NetConnection - network connection.

For example UDP:

  NetConnection connection;
  connection.setMode(NC_UDP);
  connection.setPort(2000);
  connection.setAddr(0,0,0,0);
  connection.open();
  char data[256];
  connection.write(data,256);
  while (connection.read(data,256)==0);
  unsigned _int32 recvAddr=connection.addr();
  connection.setAddr(192,168,102,10);
  while (connection.write(data,256)==0);
  connection.close();

For example TCP client:

  NetConnection connection;
  connection.setMode(NC_TCP);
  connection.setPort(2000);
  connection.setAddr(192,168,102,20);
  connection.connect();
  char data[256];
  connection.write(data,256);
  connection.close();
See Also
csad: platform

Member Enumeration Documentation

socket mode

Enumerator
NC_TCP 

create TCP connection

NC_UDP 

create UDP connection

NC_RAW 

create RAW connection