Professional Documents
Culture Documents
// Libraries
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include<pthread.h>
#include <stdbool.h>
#include <time.h>
//Socket
// Server Information
servaddr.sin_addr.s_addr = INADDR_ANY;
servaddr.sin_port = htons(PORT);
memset(&buffer, 0, sizeof(buffer));
// Bind
// listen
listen(sockfd, 10);
Int len=sizeof(cliaddr);
int n=recvfrom(sockfd, (char *)buffer, MAXLINE, MSG_WAITALL, ( struct sockaddr *) &cliaddr, &len);
buffer[n]='\0';
sendto(sockfd, (const char *)hello, strlen(hello), MSG_CONFIRM, (const struct sockaddr *) &cliaddr,
sizeof(cliaddr));
Int len=sizeof(servaddr);
int n=recvfrom(sockfd, (char *)buffer, MAXLINE, MSG_WAITALL, ( struct sockaddr *) &servaddr, &len);
buffer[n]='\0';
sendto(sockfd, (const char *)hello, strlen(hello), MSG_CONFIRM, (const struct sockaddr *) &servaddr,
sizeof(servaddr));
// Connect
// Accept
// Receiving data
buffer[n]='\0';
// sending data
// Close Socket
close(sockfd);
// Fork
if(pid == -1){
continue;
f(pid == 0){
// child process
else {
// parent process
// threads
void* function_Name (void *ptr) // this function will have only one parameter
{}
pthread_join(tid, NULL);
pthread_exit(NULL);
// conversions
time_t t = time(NULL);
local = localtime(&t);
char* ip = inet_ntoa(cliaddr.sin_addr);
fclose(file);
// Alternate of Printf(“”);
write(1,data,strlen(data));
// TCP client server (Iterative ) flow chart