Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 748 was 632, checked in by dumenim, 17 years ago

networkstuff bluber fubber

File size: 1.9 KB
RevLine 
[438]1#include <iostream>
2#include <string>
3#include "PacketManager.h"
4#include "Client.h"
5
[632]6#ifdef WIN32
7#include <windows.h>
8#define usleep(x) Sleep((x)/1000)
9#else
10#include <unistd.h>
11#endif
12
[438]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;
[632]30  char message[10000];
31  char signs[] = "abcdefghijklmnopqrstuvwxy";
[438]32  while (true) {
[459]33          client.tick(0);
[632]34         
35          std::cout << "your message2: ";
36          for ( int i=0; i<9999; i++ ) {
37            message[i] = signs[0];
38          }
39          message[9999] = 'z';
40          std::string str( message );
41          client.sendChat( str );
42          std::cout << str << std::endl;
43          std::cin.get(); std::cin.get();
[438]44  }
[448]45
46
47
[441]48}
[448]49
50void listener(){
[601]51       
[448]52  const int PORT = 55556;
53  std::cout << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << std::endl;
54  std::string str;
55  std::getline(std::cin, str);
56  std::cout << "You entered: " << str << std::endl;
57  if(str.compare("")==0)
58    str="127.0.0.1";
59
60  Client client( str, PORT );
61  if ( client.establishConnection() )
62          std::cout << "connection established" << std::endl;
63  else std::cout << "problems establishing connection" << std::endl;
64
65  while (true) {
[459]66          client.tick(0);
[448]67          usleep(100);
68  }
69
70
71
72}
73
74
75int main(int argc, char **argv[]){
76  std::string in;
77  std::cout << "Please choose: sender(s) oder listener(l)" << std::endl;
78  std::getline(std::cin, in);
79  if(in.compare("l")==0)
80    listener();
81  else if(in.compare("s")==0)
82    sender();
83  else
84    std::cout << "wrong answer" << std::endl;
85}
Note: See TracBrowser for help on using the repository browser.