|
#include <stdio.h> #include <errno.h> #include <unistd.h> #include <stdlib.h> #include <sys/socket.h> #include <sys/un.h> #define SERVER "/tmp/serversocket" #define CLIENT "/tmp/mysocket" #define MAXMSG 512 #define MESSAGE "Aloo!!! Adanaaa, Adana mi orasi?!?" int main (void) { extern int make_named_socket (const char *name); int sock; char message[MAXMSG]; struct sockaddr_un name; size_t size; int nbytes; /* Soketi oluşturalim. */ sock = make_named_socket (CLIENT); /* Sunucu soket adresini ilklendirelim. */ name.sun_family = AF_LOCAL; strcpy (name.sun_path, SERVER); size = strlen (name.sun_path) + sizeof (name.sun_family); /* Datagramı gönderelim. */ nbytes = sendto (sock, MESSAGE, strlen (MESSAGE) + 1, 0, (struct sockaddr *) & name, size); if (nbytes < 0) { perror ("sendto (client)"); exit (EXIT_FAILURE); } /* Yanıt bekleyelim. */ nbytes = recvfrom (sock, message, MAXMSG, 0, NULL, 0); if (nbytes < 0) { perror ("recfrom (client)"); exit (EXIT_FAILURE); } /* Durumu bildirelim. */ fprintf (stderr, "İstemci: gelen ileti: %s\n", message); /* Ortalığı temizleyelim. */ remove (CLIENT); close (sock); }
|