Skip to content

Commit

Permalink
Working project
Browse files Browse the repository at this point in the history
  • Loading branch information
tainfante committed Feb 25, 2018
0 parents commit bacb579
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 0 deletions.
Binary file added Debug/ClientTCP
Binary file not shown.
43 changes: 43 additions & 0 deletions Debug/makefile
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
8 changes: 8 additions & 0 deletions Debug/objects.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
################################################################################
# Automatically-generated file. Do not edit!
################################################################################

USER_OBJS :=

LIBS :=

17 changes: 17 additions & 0 deletions Debug/sources.mk
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 added Debug/src/ClientTCP.o
Binary file not shown.
24 changes: 24 additions & 0 deletions Debug/src/subdir.mk
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 ' '


96 changes: 96 additions & 0 deletions src/ClientTCP.c
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;
}

0 comments on commit bacb579

Please sign in to comment.