All pastes #229774 Raw Edit

Mine

public text v1 · immutable
#229774 ·published 2006-10-30 22:40 UTC
rendered paste body
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
//#include <netdb.h>
#include <unistd.h>
//#include <signal.h>
#include <fcntl.h>
//#include <errno.h>
//#include <sys/time.h>
//#include <memory.h>


int main () {

int server_port = 9987; // port number to communicate on
int backlog = 5; //assign number of listen connections

int sd, nsd;
struct sockaddr_in server; /* /usr/include/netinet/in.h*/
struct sockaddr_in client;
socklen_t sin_size;
printf("Creating Socket");
sd = socket( AF_INET, SOCK_STREAM, 0 ); // create the socket sd
if (sd == -1) perror("Could not create socket");
bzero( (char*)&server, sizeof(server) );	//binary-zero server
server.sin_family = AF_INET;			//set sin_family
server.sin_port = htons(server_port);		//convert port to short
server.sin_addr.s_addr= htonl( INADDR_ANY );	//convert host to long
bind( sd, (struct sockaddr*) &server, sizeof(server) ); //binds socket address to IP
listen( sd, backlog );				//listens for connections...

sin_size = sizeof( struct sockaddr_in);

while (1) {
nsd= accept( sd, (struct sockaddr*) &client, &sin_size );
//read()/write();
//close( nsd);
}
close( sd );


return 0;

}