Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <netdb.h>
- #include <stdio.h>
- int main (int argc, char** argv)
- {
- int fd,cfd,i;
- socklen_t l;
- struct sockaddr_in saddr, caddr;
- fd = socket(PF_INET, SOCK_STREAM, 0);
- //printf("socket: %d\n", cfd);
- saddr.sin_family = PF_INET;
- saddr.sin_port = htons(1234);
- saddr.sin_addr.s_addr = INADDR_ANY;
- i = bind(fd, (struct sockaddr*)&saddr, sizeof(saddr));
- printf("bind: %d\n", i);
- i = listen(fd, 5);
- printf("listen: %d\n", i);
- while(1){
- l = sizeof(caddr);
- cfd = accept(fd, (struct sockaddr*)&caddr, &l);
- printf("accept: %d\n", cfd);
- write (cfd, "Hello world!\n",14);
- close(cfd);
- }
- close (fd);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement