Great Deal! Get Instant $25 FREE in Account on First Order + 10% Cashback on Every Order Order Now

client_tcp /****************Client program********************************/ /* client_tcp.c is on zeus.cs.txstate.edu open a window on zeus. compile: $gcc -o c client_tcp.c $./c eros.cs.txstate.edu */...

1 answer below »

client_tcp
****************Client program********************************
* client_tcp.c is on zeus.cs.txstate.edu
open a window on zeus.
compile:
$gcc -o c client_tcp.c
$./c eros.cs.txstate.edu
*
#include #include #include #include #include int main(int argc, char **argv){
int clientSocket;
char buffer[1024];
struct sockaddr_in serverAddr;
socklen_t addr_size;
unsigned short port;
struct hostent *hostnm;
uint32_t num, cnum;
char msg[30];
*---- Create the socket. The three arguments are: ----*
* 1) Internet domain 2) Stream socket 3) Default protocol (TCP in this case) *
clientSocket = socket(PF_INET, SOCK_STREAM, 0);
*---- Configure settings of the server address struct ----*
* Address family = Internet *
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(8000);
* Set IP address to localhost *
hostnm = gethostbyname(argv[1]);
serverAddr.sin_addr.s_addr = *((unsigned long *)hostnm->h_addr);
* Set all bits of the padding field to 0 *
memset(serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero);
*---- Connect the socket to the server using the address struct ----*
addr_size = sizeof serverAddr;
connect(clientSocket, (struct sockaddr *) &serverAddr, addr_size);
communication starts from here
send an integer to the serve
printf("enter an integer:");
scanf("%d", &num);
cnum = htonl(num);
send(clientSocket, &cnum, sizeof(cnum), 0);
receive a reply message from the serve
ecv(clientSocket, msg, sizeof(msg), 0);
printf("%s\n", msg);
close(clientSocket);
eturn 0;
}
receive an integer from the client
ecv(newSocket, &num, sizeof(num), 0);
printf("Integer received: %d\n",ntohl(num));
send a reply message to the client
strcpy(msg, "Integer received");
send(newSocket, msg, sizeof(msg), 0);
close(newSocket);
close(welcomeSocket);
eturn 0;
}
Answered 3 days AfterFeb 15, 2022

Solution

Aneshteja answered on Feb 19 2022
45 Votes
2
Name:
Professor:
Course:
Date:
Title: TCP/IP communication using Python Programming
Contents
Introduction    3
client program Using Python    3
Server ProgramUsing Python    5
Output of the Both Client and server Program    6
Conclusion    7
References    7
Introduction
In this TCP/IP communication using Python Program it will connect you both client and server using this TCP/IP to communicate with each other by sending messages
Client Program Using Python
import socket
c=socket.socket()
c.connect(('localhost',9991))
ollno=input("Enter your Rollno")
c.send(bytes(rollno,'utf-8'))
fname=input("Enter your...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here