Created
December 20, 2018 13:58
-
-
Save coder3101/eee4e1b5344719b8ac7b16dec2887e11 to your computer and use it in GitHub Desktop.
This code connects a client to the rpc-server. You need to specify the open interface of the server. It's IP in the IP_ADDR_SERVER macro. See rpc-server.c for furthur information.
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
#include <stdio.h> | |
#include <sys/socket.h> | |
#include <stdlib.h> | |
#include <netinet/in.h> | |
#include <string.h> | |
#define PORT 12345 | |
#define IP_ADDR_SERVER "192.168.43.51" //YOU MAY NEED TO CHANGE THIS ADDRESS | |
int main(){ | |
struct sockaddr_in address; | |
int sock = 0, valread; | |
struct sockaddr_in serv_addr; | |
char buffer[1024] = {0}; | |
sock = socket(AF_INET, SOCK_STREAM, 0); | |
memset(&serv_addr, '0', sizeof(serv_addr)); | |
serv_addr.sin_family = AF_INET; | |
serv_addr.sin_port = htons(PORT); | |
if(inet_pton(AF_INET, IP_ADDR_SERVER, &serv_addr.sin_addr)<=0) | |
{ | |
printf("\nInvalid address/ Address not supported \n"); | |
return -1; | |
} | |
if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) | |
{ | |
printf("\nConnection refused by server \n"); | |
return -1; | |
} | |
valread = read(sock,buffer,1024); | |
printf("%s\n",buffer); | |
printf("\nEnter the number : "); | |
scanf("%s", buffer); | |
send(sock, buffer, strlen(buffer), 0); | |
char result[21]; | |
valread = read(sock, result, 21); | |
printf("Factorial returned %s", result); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment