SWInetSocket(block_type block=blocking)Methods:
You can specify the blocking mode for this socket, see enum block_type for more information.
virtual bool bind(int port, SWBaseError *error = NULL)
virtual bool bind(int port, std::string host, SWBaseError *error = NULL)
Bind to a local network host and port. The socket will bind to any local host if you don't specify a specific host. You can specify port zero to get any free port. Returns true on success. Possible error types: notConnected and fatal.
virtual bool connect(int port, std::string hostname, SWBaseError *error = NULL)
Connect to an local or remote hostname on the specified port. Returns true on success. Possible error types: notConnected, noResponse, portInUse, notReady and fatal.
virtual std::string get_peerAddr(SWBaseError *error = NULL)
Returns a string with the peer IP address in standard numbers-and-dots notation. Returns an empty string on failure. Possible error types: notConnected and fatal.
virtual int get_peerPort(SWBaseError *error = NULL)
Returns the port used on the peer machine. Returns -1 on failure. Possible error types: notConnected and fatal.
virtual std::string get_peerName(SWBaseError *error = NULL)
Returns the hostname used by the peer. Returns an empty string on failure. Possible error types: notConnected and fatal.
virtual std::string get_hostAddr(SWBaseError *error = NULL)
Returns a string with the local IP address in standard numbers-and-dots notation. Returns an empty string on failure. Possible error types: notConnected and fatal
virtual int get_hostPort(SWBaseError *error = NULL)
Returns the port used on the local machine. Returns -1 on failure. Possible error types: notConnected and fatal
virtual std::string get_hostName(SWBaseError *error = NULL)
Returns the hostname of the local machine. Returns an empty string on failure. Possible error types: notConnected and fatal.
#include "SocketW.h" ... SWInetSocket listener; SWInetSocket *mySocket; listener.bind(5555); // or do bind(5555, "localhost") if you only listener.listen(); // want to accept local connections mySocket = (SWInetSocket *)listener.accept(); // do something with mySocket... mySocket->sendmsg("Hello Client!"); // disconnect and clean up mySocket->disconnect(); delete mySocket; |
#include "SocketW.h" ... SWInetSocket mySocket; mySocket.connect(5555, "localhost"); // or do connect(80, "slashdot.org") // if you want to talk to a webserver // do something with mySocket... string msg = mySocket.recvmsg(); // disconnect mySocket.disconnect(); |
#include "SocketW.h" ... SWInetSocket mySocket; Uint32 buf[2]; ... // fill buf[0] and buf[1] with 32bit data... ... // convert to network byte order buf[0] = htonl(buf[0]); buf[1] = htonl(buf[1]); // send mySocket.send( (char *)buf, 8); // send 2*4 bytes ... |
Copyright © 2003 Anders Lindström
Last updated 031024