TCP Echo Server – Echo Client Program using C

tcpechoServer.c #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #include <stdio.h> #include <unistd.h> #include <strings.h> #include <string.h> #define MAX_MSG 100 #define SERVER_ADDR “127.0.0.1” #define SERVER_PORT 3786 main ( ) { int sd, newSd, cliLen, n; struct sockaddr_in cliAddr, servAddr; char line[MAX_MSG], line_r[MAX_MSG]; /**********************************/ /* build server address structure */ /**********************************/ bzero((char *)&servAddr, sizeof(servAddr)); […]

Read More

UDP Client-Server Program using C

udpClient.c #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #include <stdio.h> #include <unistd.h> #include <string.h> #include <sys/time.h> #define MAX_MSG 100 #define SERVER_ADDR “127.0.0.1” #define SERVER_PORT 9227 main( ) { int sd, rc, tempLen, n; struct sockaddr_in cliAddr, remoteServAddr, tempAddr; char msg[MAX_MSG]; /**********************************/ /* build server address structure */ /**********************************/ bzero((char *)&remoteServAddr, sizeof(remoteServAddr)); remoteServAddr.sin_family […]

Read More

UDP Client-Server Program (Command Line) using C

udpClient.c #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #include <stdio.h> #include<stdlib.h> #include <unistd.h> #include <string.h> #include <strings.h> #include <sys/time.h> #define MAX_MSG 100 main(int argc,char *argv[] ) { int i, sd, rc, tempLen, n, portno; struct sockaddr_in remoteServAddr, tempAddr; struct sockaddr_in cliAddr; char server[20]; char msg[MAX_MSG]; if(argc<3) { fprintf(stderr,”Usage : %s hostname port\n […]

Read More

Concatenation of two strings sent from Client on the Server – [ TCP ] using C

tcpClient.c #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #include <stdio.h> #include <unistd.h> #include <string.h> #include <strings.h> #define MAX_MSG 100 #define SERVER_ADDR “127.0.0.1” #define CLIENT_ADDR “127.0.0.1” #define SERVER_PORT 3786 #define CLIENT_PORT 8229 main () { int sd, rc, i,n; struct sockaddr_in clientAddr, servAddr; char line[MAX_MSG]; /**********************************/ /* build server address structure */ /**********************************/ […]

Read More

Addition of two numbers on Server sent from Client [TCP] using C

tcpClient.c #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #include <stdio.h> #include <unistd.h> #include <string.h> #include <strings.h> #define MAX_MSG 100 #define SERVER_ADDR “127.0.0.1” #define CLIENT_ADDR “127.0.0.1” #define SERVER_PORT 3786 #define CLIENT_PORT 8229 main () { int sd, rc, i,n; struct sockaddr_in clientAddr, servAddr; char line[MAX_MSG]; /**********************************/ /* build server address structure */ /**********************************/ […]

Read More