-
-
Save kasramp/f270ae812b62305ca5a9048c27df030f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Client Side*/ | |
#include <stdio.h> | |
#include <sys/types.h> | |
#include <netinet/in.h> | |
#include <string.h> | |
#include <sys/socket.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
int main() | |
{ | |
int sd, con, port, i, Res; | |
char content[255]; | |
struct sockaddr_in cli; | |
if ((sd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) | |
{ | |
printf(“\nSocket problem”); | |
return 0; | |
} | |
bzero((char *)&cli, sizeof(cli)); | |
cli.sin_family = AF_INET; | |
printf("ENTER PORT NO:\n"); | |
scanf("% d", &port); | |
cli.sin_port = htons(port); | |
cli.sin_addr.s_addr = htonl(INADDR_ANY); | |
con = connect(sd, (struct sockaddr *)&cli, sizeof(cli)); | |
if (con == -1) | |
{ | |
printf("\nConnection error "); | |
return 0; | |
} | |
if (fork()) | |
{ | |
printf("\nEnter the data to be send type exit for stop:\n\e[1;33m"); | |
gets(content); | |
while (strcmp(content, "exit") != 0) | |
{ | |
gets(content); | |
send(sd, content, 255, 0); | |
} | |
send(sd,”exit”, 5, 0); | |
} | |
else | |
{ | |
i = recv(sd, content, 255, 0); | |
while (strcmp(content, "exit") != 0) | |
{ | |
printf("\e[1;34mServer: %s\e[1;33m\n", content); | |
i = recv(sd, content, 255, 0); | |
} | |
send(sd, "exit", 5, 0); | |
} | |
close(sd); | |
printf("\e[0m"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment