Last change
on this file since 259 was
226,
checked in by mmc, 19 years ago
|
- Added code for Wei's visualization server.
- Fixed the energyLevels widget so that it doesn't barf when the
user attempts to download its contents.
|
File size:
1.2 KB
|
Line | |
---|
1 | /* |
---|
2 | * RenderServer.cpp: server with OpenRenderer engine |
---|
3 | */ |
---|
4 | |
---|
5 | #include "RenderServer.h" |
---|
6 | |
---|
7 | |
---|
8 | RenderServer::RenderServer(){} |
---|
9 | |
---|
10 | RenderServer::RenderServer(int port_num){ |
---|
11 | |
---|
12 | socket_num = port_num; |
---|
13 | |
---|
14 | //init socket server |
---|
15 | std::cout << "server up and running....\n"; |
---|
16 | |
---|
17 | try |
---|
18 | { |
---|
19 | // Create the socket |
---|
20 | server_socket = new ServerSocket(socket_num); |
---|
21 | server_socket->set_non_blocking(true); |
---|
22 | |
---|
23 | } |
---|
24 | catch ( SocketException& e ) |
---|
25 | { |
---|
26 | std::cout << "Exception was caught:" << e.description() << "\nExiting.\n"; |
---|
27 | } |
---|
28 | } |
---|
29 | |
---|
30 | |
---|
31 | std::string& RenderServer::listen(){ |
---|
32 | |
---|
33 | if(!open_socket.is_connected()){ |
---|
34 | if(server_socket->accept(open_socket)){ |
---|
35 | printf("server: connection accepted\n"); |
---|
36 | try |
---|
37 | { |
---|
38 | std::string data; |
---|
39 | open_socket >> data; |
---|
40 | //std::cout << "server: msg received - " << data << "\n"; |
---|
41 | |
---|
42 | open_socket << data; |
---|
43 | //return true; |
---|
44 | } |
---|
45 | catch ( SocketException& ) { /*return false;*/} |
---|
46 | } |
---|
47 | } |
---|
48 | else{ |
---|
49 | try |
---|
50 | { |
---|
51 | std::string data; |
---|
52 | open_socket >> data; |
---|
53 | //std::cout << "server: msg received - " << data << "\n"; |
---|
54 | |
---|
55 | open_socket << data; |
---|
56 | |
---|
57 | //return true; |
---|
58 | } |
---|
59 | catch ( SocketException& ) { /*return false;*/} |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
Note: See
TracBrowser
for help on using the repository browser.