Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/network/dummyclient3.cc @ 601

Last change on this file since 601 was 601, checked in by dumenim, 16 years ago

blub

File size: 1.8 KB
RevLine 
[438]1#include <iostream>
2#include <string>
3#include "PacketManager.h"
4#include "Client.h"
[536]5
6#ifdef WIN32
7#include <windows.h>
8#define usleep(x) Sleep((x)/1000)
9#else
10#include <unistd.h>
11#endif
[438]12
13using namespace network;
14
[448]15void sender(){
16
[438]17  network::PacketGenerator pck;
[441]18  const int PORT = 55556;
[438]19  std::cout << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << std::endl;
20  std::string str;
21  std::getline(std::cin, str);
22  std::cout << "You entered: " << str << std::endl;
23  if(str.compare("")==0)
24    str="127.0.0.1";
[448]25
[438]26  Client client( str, PORT );
27  if ( client.establishConnection() )
[448]28          std::cout << "connection established" << std::endl;
[441]29  else std::cout << "problems establishing connection" << std::endl;
[448]30
[438]31  while (true) {
[459]32          client.tick(0);
[448]33          std::cout << "your message: ";
34          std::getline( std::cin, str );
35          client.sendChat( str );
[601]36          std::cout << "sent message" << std::endl;
[438]37  }
[448]38
39
40
[441]41}
[448]42
43void listener(){
[601]44       
[448]45  const int PORT = 55556;
46  std::cout << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << std::endl;
47  std::string str;
48  std::getline(std::cin, str);
49  std::cout << "You entered: " << str << std::endl;
50  if(str.compare("")==0)
51    str="127.0.0.1";
52
53  Client client( str, PORT );
54  if ( client.establishConnection() )
55          std::cout << "connection established" << std::endl;
56  else std::cout << "problems establishing connection" << std::endl;
57
58  while (true) {
[459]59          client.tick(0);
[448]60          usleep(100);
61  }
62
63
64
65}
66
67
68int main(int argc, char **argv[]){
69  std::string in;
70  std::cout << "Please choose: sender(s) oder listener(l)" << std::endl;
71  std::getline(std::cin, in);
72  if(in.compare("l")==0)
73    listener();
74  else if(in.compare("s")==0)
75    sender();
76  else
77    std::cout << "wrong answer" << std::endl;
78}
Note: See TracBrowser for help on using the repository browser.