19.01.2015 Views

Sockets Tutorial PDF file

Sockets Tutorial PDF file

Sockets Tutorial PDF file

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

IMPLEMENTING AN ECHO SERVER..<br />

Program at the “server –end”<br />

* Create a stream socket<br />

if((sd= socket(AF_INET,SOCK_STREAM,0) ) = = -1) {<br />

fprintf(stderr, “cant create a socket”);<br />

exit (1); }<br />

* Bind some add to the socket<br />

bzero((char *)& server ,sizeof(struct sockaddr_in));<br />

server.sin_family =AF_INET;<br />

server.sin_port = htons(port);<br />

server.sin_addr.s_addr = htons(INADDR_ANY);<br />

* Queue up to 5 connect requests<br />

listen(sd ,5);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!