Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure what you are looking for, but this could be of some help, its in Unix:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;sys/types.h&gt; #include &lt;sys/socket.h&gt; #include &lt;netinet/in.h&gt; #include &lt;bstring.h&gt; /* bzero(), bcopy() */ #include &lt;unistd.h&gt; /* read(), write(), close() */ #include &lt;errno.h&gt; #include &lt;sys/signal.h&gt; int obtain_socket(int port); void show_message(int sd); void close_down(int sigtype); #define PORT 2001 /* default port for server */ #define SIZE 512 /* max length of character string */ int ssockfd; /* socket for PORT; global for close_down() */ int main() { int sd, client_len; struct sockaddr_in client; signal(SIGINT, close_down); /* use close_down() to terminate */ printf("Listen starting on port %d\n", PORT); ssockfd = obtain_socket(PORT); while(1) { client_len = sizeof(client); if ((sd = accept(ssockfd, (struct sockaddr *) &amp;client, &amp;client_len)) &lt; 0) { perror("accept connection failure"); exit(4); } show_message(sd); close(sd); } return 0; } int obtain_socket(int port) /* Perform the first four steps of creating a server: create a socket, initialise the address data structure, bind the address to the socket, and wait for connections. */ { int sockfd; struct sockaddr_in serv_addr; /* open a TCP socket */ if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) &lt; 0) { perror("could not create a socket"); exit(1); } /* initialise socket address */ bzero((char *)&amp;serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); serv_addr.sin_port = htons(port); /* bind socket to address */ if (bind(sockfd, (struct sockaddr *)&amp;serv_addr, sizeof(serv_addr)) &lt; 0) { perror("could not bind socket to address"); exit(2); } /* set socket to listen for incoming connections */ /* allow a queue of 5 */ if (listen(sockfd, 5) == -1) { perror("listen error"); exit(3); } return sockfd; } void show_message(int sd) /* Print the incoming text to stdout */ { char buf[SIZE]; int no; while ((no = read(sd, buf, SIZE)) &gt; 0) write(1, buf, no); /* write to stdout */ } void close_down(int sigtype) /* Close socket connection to PORT when ctrl-C is typed */ { close(ssockfd); printf("Listen terminated\n"); exit(0); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload