Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NetUITCP Class Reference

#include <netui.h>

Static Public Member Functions

static SOCKETALT createSocket (const char *host, unsigned short port, SocketSet &set)
 
static ServerSocketcreateServerSocket (unsigned short port, SocketSet &set)
 

Detailed Description

Definition at line 40 of file netui.h.

Member Function Documentation

ServerSocket * NetUITCP::createServerSocket ( unsigned short  port,
SocketSet set 
)
static

Definition at line 178 of file netui.cpp.

References COUT, NetUIBase::createServerSocket(), NetUIBase::lookupHost(), and SERVER_PORT.

Referenced by AccountServer::start(), and NetServer::start().

179 {
180  COUT<<"enter "<<__PRETTY_FUNCTION__<<std::endl;
181  //If port is not given, use the defaults ones --> do not work with specified ones yet... well, didn't try
182  if (port == 0) port = SERVER_PORT;
183  AddressIP local_ip = NetUIBase::lookupHost( "0.0.0.0", port );
184  if (local_ip.sin_port == 0)
185  return NULL;
186  int local_fd = NetUIBase::createServerSocket( local_ip, true );
187  if (local_fd == -1)
188  return NULL;
189  COUT<<"Listening on socket "<<local_fd<<std::endl
190  <<"*** ServerSocket FD : "<<local_fd<<std::endl;
191  return new ServerSocketTCP( local_fd, local_ip, set );
192 }
SOCKETALT NetUITCP::createSocket ( const char *  host,
unsigned short  port,
SocketSet set 
)
static

Definition at line 153 of file netui.cpp.

References COUT, NetUIBase::createClientSocket(), SOCKETALT::get_fd(), NetUIBase::lookupHost(), SERVER_PORT, and SOCKETALT::set_nonblock().

Referenced by NetClient::init().

154 {
155  COUT<<"enter "<<__PRETTY_FUNCTION__<<std::endl;
156  //If port is not given, use the defaults ones --> do not work with specified ones yet... well, didn't try
157  if (srv_port == 0)
158  srv_port = SERVER_PORT;
159  AddressIP remote_ip = NetUIBase::lookupHost( host, srv_port );
160  if (remote_ip.sin_port == 0) {
161  SOCKETALT ret;
162  return ret;
163  }
164  int local_fd = NetUIBase::createClientSocket( remote_ip, true, false );
165  if (local_fd == -1) {
166  SOCKETALT ret; //( -1, SOCKETALT::TCP, remote_ip );
167  return ret;
168  }
169  COUT<<"Connected to "<<inet_ntoa( remote_ip.sin_addr )<<":"<<srv_port<<std::endl;
170 
171  SOCKETALT ret( local_fd, SOCKETALT::TCP, remote_ip, set );
172  if (ret.set_nonblock() == false)
173  COUT<<"WARNING: TCP client socket may be in blocking mode"<<std::endl;
174  COUT<<"SOCKETALT FD: "<<ret.get_fd()<<std::endl;
175  return ret;
176 }

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