c++ chat programmieren

Gast #3435273
Lesenswert?

hallo ich möchte einen chat programmieren wo der client (programmier ich 
später) auf den server eine nachricht sendet und der server sendet das 
dann auf den 2. client hier mein code bis jetzt:


#include <windows.h>
#include <conio.h>
#include <iostream>
#include <string>
 int main() {
  using namespace std;
    string fehler;
    int port;
  string erfolgreich;
  string falsch;
  string viels;
  //ip adresse
  char hostname[255];
 char *szIPAddress;
 WORD wVer;
 WSADATA wData;
 PHOSTENT hostinfo;
 wVer = MAKEWORD( 2, 0 );

 if ( WSAStartup( wVer, &wData ) == 0 )
 {
  if( gethostname ( hostname, sizeof(hostname)) == 0)
  {
   if((hostinfo = gethostbyname(hostname)) != NULL)
   {
    szIPAddress = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
   }
  }
 WSACleanup();
 }

  cout<<"deine ip ist: "<<szIPAddress<<endl;
  cout <<"bitte port eingeben!" <<endl;
  cin >> port;
  cout <<endl;
  cout << "server port: " << port <<endl ;
  cout<<"bitte Taste dr\x81 cken"<<endl;
  getch();
  viels = "viel spass!";
  falsch = "der befehl ist nicht korrekt";
  erfolgreich = "alles ging erfolgreich!";
  fehler = "bitte kontaktiere einen server administrator um den fehler 
zu beheben!";
  cout << erfolgreich <<endl << viels <<endl;
  bool slotsfrei;
  slotsfrei = true;
if(slotsfrei == true)
{
cout << "es sind server slots Frei!";
}
else
{
cout << "es alle Server Slots besetzt!";
}


}
Gast #3435288
Lesenswert?

1
#include <windows.h> 
2
#include <conio.h> 
3
#include <iostream>
4
#include <string>
5
 int main() {
6
  using namespace std;
7
    string fehler;
8
    int port;
9
  string erfolgreich;
10
  string falsch;
11
  string viels;
12
  //ip adresse
13
  char hostname[255];
14
 char *szIPAddress;
15
 WORD wVer;
16
 WSADATA wData;
17
 PHOSTENT hostinfo;
18
 wVer = MAKEWORD( 2, 0 );
19

20
 if ( WSAStartup( wVer, &wData ) == 0 )
21
 {
22
  if( gethostname ( hostname, sizeof(hostname)) == 0)
23
  {
24
   if((hostinfo = gethostbyname(hostname)) != NULL)
25
   {
26
    szIPAddress = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
27
   }
28
  }
29
 WSACleanup();
30
 } 
31

32
  cout<<"deine ip ist: "<<szIPAddress<<endl;
33
  cout <<"bitte port eingeben!" <<endl;
34
  cin >> port;
35
  cout <<endl;
36
  cout << "server port: " << port <<endl ;
37
  cout<<"bitte Taste dr\x81 cken"<<endl;
38
  getch(); 
39
  viels = "viel spass!";
40
  falsch = "der befehl ist nicht korrekt";
41
  erfolgreich = "alles ging erfolgreich!";
42
  fehler = "bitte kontaktiere einen server administrator um den fehler zu beheben!";    
43
  cout << erfolgreich <<endl << viels <<endl;
44
  bool slotsfrei;
45
  slotsfrei = true;
46
if(slotsfrei == true)
47
{
48
cout << "es sind server slots Frei!";
49
}
50
else
51
{
52
cout << "es alle Server Slots besetzt!";
53
}
54

55
      
56
}
Gast #3435289
Lesenswert?

1
#include <windows.h> 
2
#include <conio.h> 
3
#include <iostream>
4
#include <string>
5
 int main() {
6
  using namespace std;
7
    string fehler;
8
    int port;
9
  string erfolgreich;
10
  string falsch;
11
  string viels;
12
  //ip adresse
13
  char hostname[255];
14
 char *szIPAddress;
15
 WORD wVer;
16
 WSADATA wData;
17
 PHOSTENT hostinfo;
18
 wVer = MAKEWORD( 2, 0 );
19

20
 if ( WSAStartup( wVer, &wData ) == 0 )
21
 {
22
  if( gethostname ( hostname, sizeof(hostname)) == 0)
23
  {
24
   if((hostinfo = gethostbyname(hostname)) != NULL)
25
   {
26
    szIPAddress = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
27
   }
28
  }
29
 WSACleanup();
30
 } 
31

32
  cout<<"deine ip ist: "<<szIPAddress<<endl;
33
  cout <<"bitte port eingeben!" <<endl;
34
  cin >> port;
35
  cout <<endl;
36
  cout << "server port: " << port <<endl ;
37
  cout<<"bitte Taste dr\x81 cken"<<endl;
38
  getch(); 
39
  viels = "viel spass!";
40
  falsch = "der befehl ist nicht korrekt";
41
  erfolgreich = "alles ging erfolgreich!";
42
  fehler = "bitte kontaktiere einen server administrator um den fehler zu beheben!";    
43
  cout << erfolgreich <<endl << viels <<endl;
44
  bool slotsfrei;
45
  slotsfrei = true;
46
if(slotsfrei == true)
47
{
48
cout << "es sind server slots Frei!";
49
}
50
else
51
{
52
cout << "es alle Server Slots besetzt!";
53
}
54

55
      
56
}
Gast #3435359
Lesenswert?

C++ schrieb:
>> pls antwortet

Du hast immer noch keine Frage gestellt, auf die man antworten könnte.

C++ schrieb:
> sockets sind mir zu schewer

Darf man fragen, warum du dann was programmieren willst, bei dem Sockets 
so ziemlich der wichtigste Bestandteil sind?

C++ schrieb:
> und ich habe kein book alles neu zu coden

Und was erwartest du nun vom Forum? Daß jemand hier deine Hausaufgaben 
für dich erledigt?

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren