18. Mai 201015 j Hi, ich probiere mich gerade in der Programmierung von Sockets unter C (Linux). Dabei habe ich folgenden Code (Nicht unbedingt schön): #include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> int main() { int s = -1; struct sockaddr_in serverAddr; inet_pton(AF_INET, "127.0.0.1", &serverAddr.sin_addr); serverAddr.sin_port = htons(9002); serverAddr.sin_family = AF_INET; s = socket(AF_INET, SOCK_STREAM, 0); if (s == -1) { printf("socket() failed\n"); return 2; } if (bind(s, (struct sockaddr*)(&serverAddr), sizeof(serverAddr)) == -1) { printf("bind() failed\n"); return 2; } if (listen(s, 3) == -1) { printf("listen() failed\n"); return 2; } struct sockaddr_in client; int cliSize; int c; cliSize = sizeof(client); c = accept(s, (struct sockaddr *)(&client), &cliSize); printf("Verbindung von %s\n", inet_ntoa(client.sin_addr)); char message[] = "Hat funktioniert\r\n"; int bytesSent = send(s, message, strlen(message), 0); printf(bytesSent + " bytes sent"); return 0; if (bytesSent == -1) { printf("send() failed"); return 2; } else { printf(bytesSent + " bytes sent"); } close(c); } } Das Problem ist, dass das Programm nach dem Senden von "Verbindung von..." nicht weitermacht. Selbst, wenn ich eine Ausgabe direkt im Anschluss mache, wird diese nicht mehr ausgegeben.
Archiv
Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.