Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

C & Sockets

Empfohlene Antworten

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.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.