Anzeige:
Ergebnis 1 bis 4 von 4

Thema: [Sprache C] Rausfinden ob Socketverbindung noch 'da' ist

  1. #1
    Registrierter Benutzer Avatar von mrsuicide
    Registriert seit
    11.04.2003
    Beiträge
    38

    Question [Sprache C] Rausfinden ob Socketverbindung noch 'da' ist

    Ich habe mit socket() ein Socket erstellt und so einen Multithread Server zusammen.
    Ich befine mich in der Hauptschleife.
    Nun wie kann ich rausfinden ob die Verbindung zum Client unterbrochen/der Client disconnected ist??
    GreeZ,
    Mr. Suicide!

  2. #2
    Registrierter Benutzer
    Registriert seit
    08.11.2002
    Ort
    Hennef
    Beiträge
    106
    hallo,

    aus
    man 7 socket:

    SIGNALS
    When writing onto a connection-oriented socket that has
    been shut down (by the local or the remote end) SIGPIPE is
    sent to the writing process and EPIPE is returned. The
    signal is not sent when the write call specified the
    MSG_NOSIGNAL flag.

    When requested with the FIOCSETOWN fcntl or SIOCSPGRP
    ioctl, SIGIO is sent when an I/O event occurs. It is pos-
    sible to use poll(2) or select(2) in the signal handler to
    find out which socket the event occurred on. An alterna-
    tive (in Linux 2.2) is to set a realtime signal using the
    F_SETSIG fcntl; the handler of the real time signal will
    be called with the file descriptor in the si_fd field of
    its siginfo_t. See fcntl(2) for more information.


    gruß

  3. #3
    Registrierter Benutzer Avatar von mrsuicide
    Registriert seit
    11.04.2003
    Beiträge
    38
    Wie mache ich das?
    Muss ich da immer send(), write() oder recv() verwenden?
    Was ist wenn es einfach nur eine Verbindung sein soll, die darauf hinausläuft den Server zu signalisieren, dass wenn sie getrennt ist der Client offline ist?
    Geht das auch bei nonblocking sockets?
    Geändert von mrsuicide (12-04-2003 um 15:21 Uhr)
    GreeZ,
    Mr. Suicide!

  4. #4
    Registrierter Benutzer
    Registriert seit
    08.11.2002
    Ort
    Hennef
    Beiträge
    106
    hallo,

    man kann auch SO_KEEPALIVE verwenden.
    Sendet auch ein SIGPIPE wenn die Verbindung unterbrochen ist.
    ohne vorher ein send,write oder recv zu benutzten.
    aus man socket:

    The communications protocols which implement a SOCK_STREAM
    ensure that data is not lost or duplicated. If a piece of
    data for which the peer protocol has buffer space cannot
    be successfully transmitted within a reasonable length of
    time, then the connection is considered to be dead. When
    SO_KEEPALIVE is enabled on the socket the protocol checks
    in a protocol-specific manner if the other end is still
    alive. A SIGPIPE signal is raised if a process sends or
    receives on a broken stream; this causes naive processes,
    which do not handle the signal, to exit.

    zum setzten von SO_KEEPALIVE benutzt man dann setsockopt().

    gruß

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •