/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Christoph Renner, David Hasenfratz co-programmer: */ /* this is for debug output. It just says, that all calls to PRINT() belong to the DEBUG_MODULE_NETWORK module For more information refere to https://www.orxonox.net/cgi-bin/trac.cgi/wiki/DebugOutput */ #define DEBUG_MODULE_NETWORK /* include your own header */ #include "network_socket.h" /* header for debug output */ #include "debug.h" /** * Default constructor */ NetworkSocket::NetworkSocket() { /* set the class id for the base object */ this->setClassID(CL_NETWORK_SOCKET, "NetworkSocket"); /* Init SDL_net */ if(SDLNet_Init()==-1) { PRINTF(1)("SDLNet_Init: %s\n", SDLNet_GetError()); return; } else PRINTF(5)("SDL_net initialized\n"); } /** * Default destructor */ NetworkSocket::~ NetworkSocket( ) { /* Quit SDL_net */ SDLNet_Quit(); PRINTF(5)("SDL_net shutdown\n"); } /** * This function establishes a TCP/UDP connection to a given server (function argument). * It is called by the NetworkStream. It creates a TCP/UDP socket for the connection. */ void NetworkSocket::connectToServer(IPaddress ip, unsigned int port) { /* Connect to the host and port contained in ip using a TCP connection. */ tcpSocket = SDLNet_TCP_Open(&ip); if(!tcpSocket) { PRINTF(1)("SDLNet_TCP_Open: %s\n", SDLNet_GetError()); return; } } /** * Tells the NetworkSocket to listen on a specific port for incoming connections. * NetworkSocket::writeBytes(...) will have no effect until there is a valuable connection. */ void listen(unsigned int port) { } /** * DTears down a TCP/UDP connection. */ void NetworkSocket::disconnectServer( ) { /* Close the connection */ SDLNet_TCP_Close(tcpSocket); } /** * This function writes some bytes (data) to the network connection (if the connection is already * estabilhed) otherwise it just does nothing (silently discarding the data). And writes some * warnings */ void NetworkSocket::writeBytes(byte* data) { } /** * Reads in the bytes from the network interface and passes it to the NetworkStream. * This function must internaly be implemented/connected as a thread, since the read * functions of many network libraries are blocking an would therefore block the whole * program. * From outside, the thread shouldn't be accessible at all. */ byte* NetworkSocket::readBytes() { }