Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

small update in network_socket.cc

File size: 2.5 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, 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
36        /* Init SDL_net */
37        if(SDLNet_Init()==-1)
38        {
39        PRINTF(1)("SDLNet_Init: %s\n", SDLNet_GetError());
40    return;
41        }
42        else
43                PRINTF(5)("SDL_net initialized\n");
44
45}
46
47/**
48 * Default destructor
49 */
50NetworkSocket::~ NetworkSocket( )
51{
52
53        /* Quit SDL_net */
54        SDLNet_Quit();
55        PRINTF(5)("SDL_net shutdown\n");
56}
57
58/**
59  * This function establishes a TCP/UDP connection to a given server (function argument).
60  * It is called by the NetworkStream. It creates a TCP/UDP socket for the connection.
61  */
62void NetworkSocket::connectToServer(IPaddress ip, unsigned int port)
63{
64
65        /* Connect to the host and port contained in ip using a TCP connection. */
66        tcpSocket = SDLNet_TCP_Open(&ip);
67        if(!tcpSocket)
68        {
69    PRINTF(1)("SDLNet_TCP_Open: %s\n", SDLNet_GetError());
70    return;
71        }
72
73}
74
75/**
76  * Tells the NetworkSocket to listen on a specific port for incoming connections.
77  * NetworkSocket::writeBytes(...) will have no effect until there is a valuable connection.
78  */
79void listen(unsigned int port)
80{
81}
82
83/**
84 * DTears down a TCP/UDP connection.
85 */
86void NetworkSocket::disconnectServer( )
87{
88
89        /* Close the connection */
90        SDLNet_TCP_Close(tcpSocket);
91
92}
93
94/**
95  * This function writes some bytes (data) to the network connection (if the connection is already
96  * estabilhed) otherwise it just does nothing (silently discarding the data). And writes some
97  * warnings
98  */
99void NetworkSocket::writeBytes(byte* data)
100{
101}
102
103 /**
104  * Reads in the bytes from the network interface and passes it to the NetworkStream.
105  * This function must internaly be implemented/connected as a thread, since the read
106  * functions of many network libraries are blocking an would therefore block the whole
107  * program.
108  * From outside, the thread shouldn't be accessible at all.
109  */
110byte* NetworkSocket::readBytes()
111{
112}
Note: See TracBrowser for help on using the repository browser.