{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

chatappsocetprog.docx - Chat application using TCP NAME...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Chat application using TCP NAME: SINGU SAI VARUN TEJA CHOWDARY REG.NO: 15BCE0375 SLOT: L9+L10 FACULTY: ANANDA KUMAR S TASK: Chat application using TCP CODE: #include<stdio.h> #include<stdlib.h> #include<sys/types.h> #include<sys/socket.h> #include<string.h> #include<netinet/in.h> #include<pthread.h> #define PORT 4444 #define BUF_SIZE 2000 #define CLADDR_LEN 100 void * receiveMessage(void * socket) { int sockfd, ret; char buffer[BUF_SIZE];
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
sockfd = (int) socket; memset(buffer, 0, BUF_SIZE); for (;;) { ret = recvfrom(sockfd, buffer, BUF_SIZE, 0, NULL, NULL); if (ret < 0) { printf("Error receiving data!\n"); } else { printf("client: "); fputs(buffer, stdout); } } } void main() { struct sockaddr_in addr, cl_addr; int sockfd, len, ret, newsockfd; char buffer[BUF_SIZE]; pid_t childpid; char clientAddr[CLADDR_LEN]; pthread_t rThread; sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) { printf("Error creating socket!\n"); exit(1); } printf("Socket created...\n"); memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = INADDR_ANY;
Background image of page 2
addr.sin_port = PORT; ret = bind(sockfd, (struct sockaddr *) &addr, sizeof(addr));
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 4
Background image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}