Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/lib/network/network_socket.cc @ 5613

Last change on this file since 5613 was 5606, checked in by hdavid, 18 years ago

network_socket.cc

File size: 2.7 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11### File Specific:
12   main-programmer: Christoph Renner, David Hasenfratz
13   co-programmer:
14*/
15
16
17
18/* this is for debug output. It just says, that all calls to PRINT() belong to the DEBUG_MODULE_NETWORK module
19   For more information refere to https://www.orxonox.net/cgi-bin/trac.cgi/wiki/DebugOutput
20*/
21#define DEBUG_MODULE_NETWORK
22
23
24/* include your own header */
25#include "network_socket.h"
26
27/* header for debug output */
28#include "debug.h"
29
30
31/**
32 * Default constructor
33 */
34NetworkSocket::NetworkSocket()
35{
36  /* set the class id for the base object */
37  this->setClassID(CL_NETWORK_SOCKET, "NetworkSocket");
38
39  /* Init SDL_net */
40  if(SDLNet_Init()==-1)
41  {
42    PRINTF(1)("SDLNet_Init: %s\n", SDLNet_GetError());
43    return;
44  }
45  else
46    PRINTF(5)("SDL_net initialized\n");
47
48  PRINTF(0)("NetworkSocket created\n");
49
50}
51
52/**
53 * Default destructor
54 */
55NetworkSocket::~ NetworkSocket( )
56{
57
58  /* Quit SDL_net */
59  SDLNet_Quit();
60  PRINTF(5)("SDL_net shutdown\n");
61}
62
63/**
64  * This function establishes a TCP/UDP connection to a given server (function argument).
65  * It is called by the NetworkStream. It creates a TCP/UDP socket for the connection.
66  */
67void NetworkSocket::connectToServer(IPaddress ip, unsigned int port)
68{
69
70  /* Connect to the host and port contained in ip using a TCP connection. */
71  tcpSocket = SDLNet_TCP_Open(&ip);
72  if(!tcpSocket)
73  {
74    PRINTF(1)("SDLNet_TCP_Open: %s\n", SDLNet_GetError());
75    return;
76  }
77
78}
79
80/**
81  * Tells the NetworkSocket to listen on a specific port for incoming connections.
82  * NetworkSocket::writeBytes(...) will have no effect until there is a valuable connection.
83  */
84void listen(unsigned int port)
85{
86}
87
88/**
89 * DTears down a TCP/UDP connection.
90 */
91void NetworkSocket::disconnectServer( )
92{
93
94  /* Close the connection */
95  SDLNet_TCP_Close(tcpSocket);
96
97}
98
99/**
100  * This function writes some bytes (data) to the network connection (if the connection is already
101  * estabilhed) otherwise it just does nothing (silently discarding the data). And writes some
102  * warnings
103  */
104void NetworkSocket::writeBytes(byte* data)
105{
106}
107
108 /**
109  * Reads in the bytes from the network interface and passes it to the NetworkStream.
110  * This function must internaly be implemented/connected as a thread, since the read
111  * functions of many network libraries are blocking an would therefore block the whole
112  * program.
113  * From outside, the thread shouldn't be accessible at all.
114  */
115byte* NetworkSocket::readBytes()
116{
117}
Note: See TracBrowser for help on using the repository browser.