Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/tutorial/src/network/dummyclient3.cc @ 872

Last change on this file since 872 was 859, checked in by landauf, 17 years ago

more or less a copy of the trunk

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