-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bacb579
Showing
7 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
################################################################################ | ||
# Automatically-generated file. Do not edit! | ||
################################################################################ | ||
|
||
-include ../makefile.init | ||
|
||
RM := rm -rf | ||
|
||
# All of the sources participating in the build are defined here | ||
-include sources.mk | ||
-include src/subdir.mk | ||
-include subdir.mk | ||
-include objects.mk | ||
|
||
ifneq ($(MAKECMDGOALS),clean) | ||
ifneq ($(strip $(C_DEPS)),) | ||
-include $(C_DEPS) | ||
endif | ||
endif | ||
|
||
-include ../makefile.defs | ||
|
||
# Add inputs and outputs from these tool invocations to the build variables | ||
|
||
# All Target | ||
all: ClientTCP | ||
|
||
# Tool invocations | ||
ClientTCP: $(OBJS) $(USER_OBJS) | ||
@echo 'Building target: $@' | ||
@echo 'Invoking: GCC C Linker' | ||
gcc -o "ClientTCP" $(OBJS) $(USER_OBJS) $(LIBS) | ||
@echo 'Finished building target: $@' | ||
@echo ' ' | ||
|
||
# Other Targets | ||
clean: | ||
-$(RM) $(EXECUTABLES)$(OBJS)$(C_DEPS) ClientTCP | ||
-@echo ' ' | ||
|
||
.PHONY: all clean dependents | ||
|
||
-include ../makefile.targets |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
################################################################################ | ||
# Automatically-generated file. Do not edit! | ||
################################################################################ | ||
|
||
USER_OBJS := | ||
|
||
LIBS := | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
################################################################################ | ||
# Automatically-generated file. Do not edit! | ||
################################################################################ | ||
|
||
OBJ_SRCS := | ||
ASM_SRCS := | ||
C_SRCS := | ||
O_SRCS := | ||
S_UPPER_SRCS := | ||
EXECUTABLES := | ||
OBJS := | ||
C_DEPS := | ||
|
||
# Every subdirectory with source files must be described here | ||
SUBDIRS := \ | ||
src \ | ||
|
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
################################################################################ | ||
# Automatically-generated file. Do not edit! | ||
################################################################################ | ||
|
||
# Add inputs and outputs from these tool invocations to the build variables | ||
C_SRCS += \ | ||
../src/ClientTCP.c | ||
|
||
OBJS += \ | ||
./src/ClientTCP.o | ||
|
||
C_DEPS += \ | ||
./src/ClientTCP.d | ||
|
||
|
||
# Each subdirectory must supply rules for building sources it contributes | ||
src/%.o: ../src/%.c | ||
@echo 'Building file: $<' | ||
@echo 'Invoking: GCC C Compiler' | ||
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" | ||
@echo 'Finished building: $<' | ||
@echo ' ' | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
============================================================================ | ||
Name : ClientTCP.c | ||
Author : Agata Dul | ||
Version : | ||
Copyright : Your copyright notice | ||
Description : Hello World in C, Ansi-style | ||
============================================================================ | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <string.h> | ||
#include <sys/types.h> | ||
#include <sys/socket.h> | ||
#include <netinet/in.h> | ||
#include <netdb.h> | ||
#include <assert.h> | ||
|
||
|
||
int main(int argc, char** argv) { | ||
system("clear"); | ||
if(argc != 3) { | ||
printf("Invalid number of arguments, please declare IP address and port number/n"); | ||
exit(1); | ||
} | ||
|
||
int master_socket; | ||
struct sockaddr_in server_addr; | ||
socklen_t server_addr_length; | ||
struct hostent *server; | ||
char *buffer_in; | ||
char *buffer_out; | ||
|
||
int buffer_size=256; | ||
|
||
|
||
|
||
|
||
if((master_socket = socket(AF_INET, SOCK_STREAM, 0))<0){ | ||
perror("Unable to create socket"); | ||
} | ||
else{ | ||
printf("Socket created, number: %d\n", master_socket); | ||
} | ||
|
||
|
||
if((server=gethostbyname(argv[1]))== NULL) { | ||
printf("Invalid IP address, check again/n"); | ||
exit(1); | ||
} | ||
server_addr_length=sizeof(server_addr); | ||
|
||
bzero((char *) &server_addr, server_addr_length); | ||
|
||
bcopy((char *) server->h_addr, (char *) &server_addr.sin_addr.s_addr, server->h_length); | ||
|
||
server_addr.sin_family = AF_INET; | ||
server_addr.sin_port = htons(atoi(argv[2])); | ||
|
||
if (connect(master_socket,(struct sockaddr *) &server_addr, server_addr_length) < 0) { | ||
perror("Unable to connect"); | ||
exit(1); | ||
} | ||
else{ | ||
printf("Connected\n"); | ||
} | ||
|
||
while(1) { | ||
|
||
puts("NEW OPERATION"); | ||
printf("Enter the wanted operation (available: sum, dif, sortup, sortdown)\n "); | ||
buffer_out = (char *) malloc(0); | ||
fgets(buffer_out,buffer_size,stdin); | ||
if((write(master_socket,buffer_out,buffer_size)) <= 0) { | ||
perror("Unable to transmit data"); | ||
exit(1); | ||
} | ||
free(buffer_out); | ||
buffer_in = (char *) malloc(4096); | ||
if((read(master_socket,buffer_in,4096)) < 0) { | ||
perror("Unable to receive result"); | ||
exit(1); | ||
} | ||
|
||
printf("The result of your operation is: %s\n END OF OPERATION\n\n",buffer_in); | ||
free(buffer_in); | ||
|
||
|
||
|
||
} | ||
|
||
return 0; | ||
} | ||
|