#1 11. Juli 2008 Woher krieg ich header datien Ist wahrscheinlich eine ziehmlich dumme frage aber ich weiß es echt nicht. Ich versuch mich mal an C++ und hab ein kleines bis mittelgroßes problem Ich wollte mir mal das volgende beispiel compilieren. Spoiler Code: [COLOR=#339900]#include <stdio.h>[/COLOR] [COLOR=#339900]#include <stdlib.h>[/COLOR] [COLOR=#339900]#include <sys/types.h>[/COLOR] [COLOR=#339900]#include <sys/socket.h>[/COLOR] [COLOR=#339900]#include <netdb.h>[/COLOR] [COLOR=#339900]#include <netinet/in.h>[/COLOR] [COLOR=#339900]#include <arpa/inet.h>[/COLOR] [COLOR=#339900]#include <unistd.h>[/COLOR] [COLOR=#339900]#include <iostream>[/COLOR] [COLOR=#0000ff]using[/COLOR] [COLOR=#0000ff]namespace[/COLOR] std; [COLOR=#339900]#define BUFFER_SIZE 1024[/COLOR] [COLOR=#0000ff]int[/COLOR] handling[COLOR=#000000]([/COLOR][COLOR=#0000ff]int[/COLOR] sock[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR] [COLOR=#ff0000]//struct pollfd ufds;[/COLOR] [COLOR=#ff0000]//ufds.fd = sock;[/COLOR] [COLOR=#ff0000]//ufds.events = POLLIN[/COLOR] [COLOR=#ff0000]//if(-1 == poll(ufds, 2, 3500))[/COLOR] [COLOR=#ff0000]//{[/COLOR] [COLOR=#ff0000]// perror("kann nicht empfangen");[/COLOR] [COLOR=#ff0000]//}[/COLOR] [COLOR=#ff0000]// first send request[/COLOR] [COLOR=#0000ff]int[/COLOR] bytes; [COLOR=#0000ff]char[/COLOR] request[COLOR=#000000][[/COLOR][COLOR=#000000]][/COLOR]=[COLOR=#666666]"GET http://www.host.de/ HTTP/1.1[COLOR=#666666][B]\n[/B][/COLOR]Host: www.host.de[COLOR=#666666][B]\n[/B][/COLOR][COLOR=#666666][B]\n[/B][/COLOR]"[/COLOR]; bytes=send[COLOR=#000000]([/COLOR]sock, request, [COLOR=#0000dd]strlen[/COLOR][COLOR=#000000]([/COLOR]request[COLOR=#000000])[/COLOR], [COLOR=#0000dd]0[/COLOR][COLOR=#000000])[/COLOR]; [COLOR=#0000ff]if[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000dd]-1[/COLOR]==bytes[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR] [COLOR=#0000dd]perror[/COLOR][COLOR=#000000]([/COLOR][COLOR=#666666]"send() failed"[/COLOR][COLOR=#000000])[/COLOR]; [COLOR=#0000ff]return[/COLOR] [COLOR=#0000dd]3[/COLOR]; [COLOR=#000000]}[/COLOR] [COLOR=#0000dd]cout[/COLOR] << [COLOR=#666666]"Request gesendet"[/COLOR] << endl; [COLOR=#0000ff]char[/COLOR] buffer[COLOR=#000000][[/COLOR]BUFFER_SIZE[COLOR=#000000]][/COLOR]; bytes = recv[COLOR=#000000]([/COLOR]sock, buffer, [COLOR=#0000dd]sizeof[/COLOR][COLOR=#000000]([/COLOR]buffer[COLOR=#000000])[/COLOR] - [COLOR=#0000dd]1[/COLOR], [COLOR=#0000dd]0[/COLOR][COLOR=#000000])[/COLOR]; [COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]bytes == [COLOR=#0000dd]-1[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#0000ff]return[/COLOR] [COLOR=#0000dd]-1[/COLOR]; buffer[COLOR=#000000][[/COLOR]bytes[COLOR=#000000]][/COLOR] = [COLOR=#666666]'[COLOR=#666666][B]\0[/B][/COLOR]'[/COLOR]; [COLOR=#0000dd]printf[/COLOR][COLOR=#000000]([/COLOR][COLOR=#666666]"%s"[/COLOR], buffer[COLOR=#000000])[/COLOR]; [COLOR=#0000ff]return[/COLOR] [COLOR=#0000dd]0[/COLOR]; [COLOR=#000000]}[/COLOR] [COLOR=#0000ff]int[/COLOR] main[COLOR=#000000]([/COLOR][COLOR=#0000ff]int[/COLOR] argc, [COLOR=#0000ff]char[/COLOR] *argv[COLOR=#000000][[/COLOR][COLOR=#000000]][/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR] [COLOR=#0000ff]int[/COLOR] s; [COLOR=#0000ff]struct[/COLOR] sockaddr_in srv; srv.[COLOR=#00eeff]sin_addr[/COLOR].[COLOR=#00eeff]s_addr[/COLOR] = inet_addr[COLOR=#000000]([/COLOR][COLOR=#666666]"80.237.241.2"[/COLOR][COLOR=#000000])[/COLOR]; srv.[COLOR=#00eeff]sin_port[/COLOR] = htons[COLOR=#000000]([/COLOR][COLOR=#0000dd]80[/COLOR][COLOR=#000000])[/COLOR]; srv.[COLOR=#00eeff]sin_family[/COLOR] = AF_INET; s = socket[COLOR=#000000]([/COLOR]AF_INET, SOCK_STREAM, [COLOR=#0000dd]0[/COLOR][COLOR=#000000])[/COLOR]; [COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]s == [COLOR=#0000dd]-1[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR] [COLOR=#0000dd]perror[/COLOR][COLOR=#000000]([/COLOR][COLOR=#666666]"socket() failed"[/COLOR][COLOR=#000000])[/COLOR]; [COLOR=#0000ff]return[/COLOR] [COLOR=#0000dd]1[/COLOR]; [COLOR=#000000]}[/COLOR] [COLOR=#0000dd]cout[/COLOR] << [COLOR=#666666]"Socket erstellt"[/COLOR] << endl; [COLOR=#ff0000]// connect[/COLOR] [COLOR=#0000ff]if[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000dd]-1[/COLOR] == connect[COLOR=#000000]([/COLOR]s, [COLOR=#000000]([/COLOR][COLOR=#0000ff]struct[/COLOR] sockaddr *[COLOR=#000000])[/COLOR]&srv, [COLOR=#0000dd]sizeof[/COLOR][COLOR=#000000]([/COLOR]srv[COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR] [COLOR=#0000dd]perror[/COLOR][COLOR=#000000]([/COLOR][COLOR=#666666]"connect() failed"[/COLOR][COLOR=#000000])[/COLOR]; [COLOR=#0000ff]return[/COLOR] [COLOR=#0000dd]2[/COLOR]; [COLOR=#000000]}[/COLOR] [COLOR=#0000dd]cout[/COLOR] << [COLOR=#666666]"Connected"[/COLOR] << endl; [COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]handling[COLOR=#000000]([/COLOR]s[COLOR=#000000])[/COLOR] == [COLOR=#0000dd]-1[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR] [COLOR=#0000dd]fprintf[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000ff]stderr[/COLOR], [COLOR=#666666]"%s: error in handling()[COLOR=#666666][B]\n[/B][/COLOR]"[/COLOR], argv[COLOR=#000000][[/COLOR][COLOR=#0000dd]0[/COLOR][COLOR=#000000]][/COLOR][COLOR=#000000])[/COLOR]; [COLOR=#0000ff]return[/COLOR] [COLOR=#0000dd]4[/COLOR]; [COLOR=#000000]}[/COLOR] close[COLOR=#000000]([/COLOR]s[COLOR=#000000])[/COLOR]; [COLOR=#0000ff]return[/COLOR] [COLOR=#0000dd]0[/COLOR]; [COLOR=#000000]}[/COLOR] Jetzt weiß ich aber nicht woher ich die header datein: sys/types.h sys/socket.h netdb.h netinet/in.h arpa/inet.h unistd.h kriege hab gesucht aber nicht wirklich was gefunden was mir weiter geholfen hat. Ich habs in Dev-C++ und Visual C++ versucht aber beiden haben diese header datein anscheinen nicht. Bitte helft mir, währe eucht sehr dankbar, für weitere Tipps zum Programmieren in C++ währe ich auch sehr dankbar! + Multi-Zitat Zitieren
#2 11. Juli 2008 AW: Woher krieg ich header datien Haste geguckt ob die *.h dateien im verzeichnis von deinem compiler überhaupt vorhanden sind. Wenn nicht kannst du mal versuchen sie hier runterzuladen und dann in das entsprechende verzeichnis zu kopieren. Kenne mich leider mit Dev-C++ und Visual C++ nicht aus und kann dir nicht die genauen ordner sagen. mfg Seriouz + Multi-Zitat Zitieren
#3 11. Juli 2008 AW: Woher krieg ich header datien Die von dir genannten Header-Dateien (sys/types.h, sys/socket.h, netdb.h, netinet/in.h, arpa/inet.h, unistd.h) sind nur auf Unix-Systemen verfügbar. Es bringt auch nix, die herunterzuladen, da die unter Windows nicht funktionieren werden. Du kannst den Source aber für Windows umschreiben (die Includes brauchst du ja nur für Netzwerkfunktionalitäten). + Multi-Zitat Zitieren
#4 12. Juli 2008 AW: Woher krieg ich header datien Kennst du vieleicht ein Tutorial wo erklärt wird wie man unter Windows so eine Verbindung aufbaut? + Multi-Zitat Zitieren
#5 12. Juli 2008 AW: Woher krieg ich header datien Winsock Tutorials Hier bitteschön. Im Grunde musst du gar nich so viel ändern, die Funktionen sind weitestgehend gleich. Aber die genauen Unterschiede kenn ich nich, sonst hätt ichs dir schon gemacht. + Multi-Zitat Zitieren
#6 29. Juli 2008 AW: Woher krieg ich header datien *hust* sys/types.h gibts auch unter windows *hust* nen bisschen Klug rn muss sein ^^ + Multi-Zitat Zitieren