Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tainfante committed Dec 1, 2017
0 parents commit edd37c3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions Debug
Submodule Debug added at 771df9
53 changes: 53 additions & 0 deletions src/ServerTCP.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
============================================================================
Name : ServerTCP.c
Author : Agata Dul
Version :
Copyright : Your copyright notice
Description : Hello World in C, Ansi-style
============================================================================
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>

int main(int argc , char *argv[]) {

int master_socket, new_socket;
struct sockaddr_in server , client;
int read_size, socket_bound;
socklen_t server_addr_length;
int opt=1;


if((master_socket = socket(AF_INET , SOCK_STREAM , 0))==-1){
perror("Errors occured during socket creating process ");
}
else{
printf("Socket created successfully\n ");
}

if( setsockopt(master_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(opt)) < 0 ) {
perror("Errors occured during setting socket options");
exit(EXIT_FAILURE);
}

server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
server.sin_port = htons(atoi(argv[1]));

server_addr_length=sizeof(server);

if((socket_bound=bind(master_socket,(struct sockaddr *)&server ,server_addr_length)) == -1){
perror("Errors occured during socket binding process ");
}
else{
printf("Socket bound successfully, port number:%d\n",atoi(argv[1]));
}

return EXIT_SUCCESS;
}

0 comments on commit edd37c3

Please sign in to comment.