Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/lib/network/network_stream.cc @ 5738

Last change on this file since 5738 was 5738, checked in by bottac, 18 years ago
File size: 2.8 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: claudio
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#define PACKAGE_SIZE  8
22
23#include "base_object.h"
24#include "network_protocol.h"
25#include "network_socket.h"
26#include "connection_monitor.h"
27#include "synchronizeable.h"
28#include "list.h"
29#include "debug.h"
30
31/* include your own header */
32#include "network_stream.h"
33
34/* probably unnecessary */
35using namespace std;
36
37
38
39NetworkStream::NetworkStream() 
40  : DataStream()
41{
42  this->init();
43  /* initialize the references */
44  this->networkSocket = new NetworkSocket();
45  this->synchronizeables = NULL;
46  this->connectionMonitor = new ConnectionMonitor();
47}
48
49
50NetworkStream::NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type) 
51  : DataStream()
52{
53  this->init();
54  this->networkSocket = new NetworkSocket( address, 88 );
55   // this->networkSocket->connectToServer(address, 88);
56
57  this->synchronizeables = &sync;
58}
59
60
61NetworkStream::NetworkStream(Synchronizeable& sync, int port, NodeType type) 
62  : DataStream()
63{
64  this->init();
65  this->networkSocket = new NetworkSocket(/* address, type */);
66 
67  this->synchronizeables = &sync;
68}
69
70
71void NetworkStream::init()
72{
73  /* set the class id for the base object */
74  this->setClassID(CL_NETWORK_STREAM, "NetworkStream");
75}
76
77
78NetworkStream::~NetworkStream()
79{
80
81 networkSocket->disconnectServer();
82
83 delete networkSocket;
84 delete connectionMonitor;
85
86}
87
88void NetworkStream::processData()
89{
90
91 
92  int ret = 0;
93 
94 
95 
96  /* DOWNSTREAM */
97  /* first of all read the synchronizeable's data: */
98
99  ret = this->synchronizeables->readBytes((byte*)downBuffer);
100        this->connectionMonitor->processPacket((byte*)downBuffer, PACKAGE_SIZE);
101        //this-> ->extractHeader(byte* data, int length);
102  /* pass the data to the network socket */
103  ret = this->networkSocket->writeBytes((byte*)downBuffer, PACKAGE_SIZE);
104  /* check if there was an error */
105  if( ret == -1) { PRINTF(0)("Error in writing data to the NetworkSocket\n");}
106 
107 
108  /* UPSTREAM */
109  /* first read 10bytes of data (debug) */
110
111  ret = 0; 
112  while(ret == 0)  ret = this->networkSocket->readBlock((byte*)upBuffer,PACKAGE_SIZE);
113  /* error checking: data read? */
114  if( ret != PACKAGE_SIZE) { PRINTF(0)("Error while reading data from the NetworkSocket\n");}
115  /* now pass the data to the sync object */
116
117  this->synchronizeables->writeBytes((byte*)upBuffer, PACKAGE_SIZE);
118
119 
120 
121
122}
123
Note: See TracBrowser for help on using the repository browser.