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