Computer Networks Lab 6
Computer Networks Lab 6
Submitted by:
Zamin Raza Abbas
COMPUTER NETWORKS(3+1)
CE-38-B SEMESTER 5TH
FALL 2018
Client Code:
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "iostream"
#include "unistd.h"
void* helloprint (void* f) {
char buffer[100];
long fd = (long) f;
while (1) {
recv(fd, buffer,100,0);
printf("Message rcvd,%s",buffer);
sleep(2);
int main()
if(fd == -1)
{
perror("SOcket Connection failed\n");
exit(1);
s_addr.sin_family =AF_INET;
s_addr.sin_port =htons(80);
inet_aton("127.0.0.1",&s_addr.sin_addr);
perror("Connect failed!\n");
exit(1);
char buffer[100];
pthread_t th;
long value = 4;
while(1)
{
//scanf("%s",&buffer);
fgets(buffer,100,stdin);
return 0;
Server Code:
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pthread.h"
#include "iostream"
#include "unistd.h"
void* helloprint ( void* info) {
char buffer[100];
while (1) {
recv(connfd, buffer,100,0);
sleep(2);
int main()
if(fd == -1)
exit(1);
addr.sin_family = AF_INET;
addr.sin_port = htons(80);
exit(1);
exit(1);
int connfd;
if(connfd == -1)
{
perror("Accept failed on socket\n");
exit(1);
char buffer[100];
pthread_t th;
long value = 4;
while(1)
//recv(connfd, buffer,100,0);
//scanf("%s",&buffer);
fgets(buffer,100,stdin)
}
}