SUMO - Simulation of Urban MObility
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
OutputDevice_Network.cpp
Go to the documentation of this file.
1
/****************************************************************************/
9
// An output device for TCP/IP Network connections
10
/****************************************************************************/
11
// SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12
// Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
13
/****************************************************************************/
14
//
15
// This file is part of SUMO.
16
// SUMO is free software: you can redistribute it and/or modify
17
// it under the terms of the GNU General Public License as published by
18
// the Free Software Foundation, either version 3 of the License, or
19
// (at your option) any later version.
20
//
21
/****************************************************************************/
22
23
24
// ==========================================================================
25
// included modules
26
// ==========================================================================
27
#ifdef _MSC_VER
28
#include <
windows_config.h
>
29
#else
30
#include <
config.h
>
31
#endif // #ifdef _MSC_VER
32
33
#include <vector>
34
#include "
OutputDevice_Network.h
"
35
#include "
foreign/tcpip/socket.h
"
36
#include "
utils/common/ToString.h
"
37
38
#ifdef CHECK_MEMORY_LEAKS
39
#include <
foreign/nvwa/debug_new.h
>
40
#endif // #ifdef CHECK_MEMORY_LEAKS
41
42
43
// ==========================================================================
44
// method definitions
45
// ==========================================================================
46
OutputDevice_Network::OutputDevice_Network
(
const
std::string& host,
47
const
int
port) {
48
mySocket
=
new
tcpip::Socket
(host, port);
49
try
{
50
mySocket
->
connect
();
51
}
catch
(
tcpip::SocketException
& e) {
52
throw
IOError
(
toString
(e.
what
()) +
" (host: "
+ host +
", port: "
+
toString
(port) +
")"
);
53
}
54
}
55
56
57
OutputDevice_Network::~OutputDevice_Network
() {
58
mySocket
->
close
();
59
delete
mySocket
;
60
}
61
62
63
std::ostream&
64
OutputDevice_Network::getOStream
() {
65
return
myMessage
;
66
}
67
68
69
void
70
OutputDevice_Network::postWriteHook
() {
71
std::string toSend =
myMessage
.str();
72
std::vector<unsigned char> msg;
73
msg.insert(msg.end(), toSend.begin(), toSend.end());
74
mySocket
->
send
(msg);
75
myMessage
.str(
""
);
76
}
77
78
79
/****************************************************************************/
build
buildd
sumo-0.16.0~dfsg
src
utils
iodevices
OutputDevice_Network.cpp
Generated on Tue Apr 16 2013 01:32:19 for SUMO - Simulation of Urban MObility by
1.8.3.1