Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5592 was 5592, checked in by rennerc, 18 years ago

resolved conflict

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