Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5650 was 5650, checked in by patrick, 18 years ago

network: finished the simple_sync program

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: 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
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 = new Synchronizeable();
46  this->connectionMonitor = new ConnectionMonitor();
47}
48
49
50NetworkStream::NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type) 
51  : DataStream(sync)
52{
53  this->init();
54  this->networkSocket = new NetworkSocket(/* address, type */);
55}
56
57
58NetworkStream::NetworkStream(Synchronizeable& sync, int port, NodeType type) 
59  : DataStream(sync)
60{
61  this->init();
62  this->networkSocket = new NetworkSocket(/* address, type */);
63}
64
65
66void NetworkStream::init()
67{
68  /* set the class id for the base object */
69  this->setClassID(CL_NETWORK_STREAM, "NetworkStream");
70}
71
72
73NetworkStream::~NetworkStream()
74{
75 delete networkSocket;
76 delete synchronizeable;
77 delete connectionMonitor;
78
79}
80
81void NetworkStream::processData()
82{
83  PRINTF(0)("process data\n");
84  byte data[10] ; // obsolete, for debugging only
85  byte* test = (byte *)data[0]; // obsolete, for debugging only
86  int ret = 0;
87 
88  byte downData[10];
89  byte upData[10];
90 
91  /* DOWNSTREAM */
92  /* first of all read the synchronizeable's data: */
93  ret = this->synchronizeable->readBytes(downData);
94  /* pass the data to the network socket */
95  ret = this->networkSocket->writeBytes(downData, ret);
96  /* check if there was an error */
97  if( ret == -1) { PRINTF(0)("Error in writing data to the NetworkSocket\n");}
98 
99 
100  /* UPSTREAM */
101  /* first read 10bytes of data (debug) */
102  ret = this->networkSocket->readBytes(upData, 0);
103  /* error checking: data read? */
104  if( ret != 10) { PRINTF(0)("Error while reading data from the NetworkSocket\n");}
105  /* now pass the data to the sync object */
106  this->synchronizeable->writeBytes(upData, 0);
107 
108 
109
110}
111
Note: See TracBrowser for help on using the repository browser.