Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(remove-comments): unnecessary comments were removed and alsobugs undefined variables were created in /client_server/fork.h, /client_server/udp_client.c and /client_server/udp_server.c #1444

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,17 @@
.vscode/
build/
git_diff.txt
*.filters
*.vcxproj
*.sln
CMakeCache.txt
cmake_install.cmake
*.log
*.stamp
*.stamp.list
*.stamp.depend
*.check_cache
*.tlog
*.bin
CMakeFiles/
output/
32 changes: 6 additions & 26 deletions client_server/bool.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2007 - INRIA
*
* Copyright (C) 2012 - 2016 - Scilab Enterprises
*
* This file is hereby licensed under the terms of the GNU GPL v2.0,
* pursuant to article 5.3.4 of the CeCILL v.2.1.
* This file was originally licensed under the terms of the CeCILL v2.1,
* and continues to be available under such terms.
* For more information, see the COPYING file which you should have received
* along with this program.
*
*/
#ifndef __BOOL_H__
#define __BOOL_H__

/* define boolean type */
#ifdef BOOL
#undef BOOL
#endif
Expand All @@ -28,28 +13,23 @@
#undef FALSE
#endif


#ifndef _MSC_VER
#ifndef _MSC_VER
typedef enum
{
FALSE = 0,
TRUE = 1
} BOOL;

#else
/* Please notice that BOOL is defined in <windef.h> */
/* BUT windef.h includes all others windows include */
/* it is better to redefine as */

typedef int BOOL;
#define FALSE 0
#define TRUE 1

#endif
/* converts BOOL to bool */
#define BOOLtobool(w) ((w != FALSE) ? true : false)

/* converts bool to BOOL */
#define booltoBOOL(w) ((w == true) ? TRUE : FALSE)
#define BOOLtobool(w) ((w != FALSE) ? true : false)

#endif /* __BOOL_H__ */
/*--------------------------------------------------------------------------*/
#define booltoBOOL(w) ((w == true) ? TRUE : FALSE)

#endif
47 changes: 12 additions & 35 deletions client_server/client.c
Original file line number Diff line number Diff line change
@@ -1,39 +1,26 @@
/**
* @file
* @author [Nairit11](https://github.com/Nairit11)
* @author [Krishna Vedala](https://github.com/kvedala)
* @brief Client side implementation of Server-Client system.
* @see client_server/server.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef _WIN32 // if compiling for Windows
#define _WINSOCK_DEPRECATED_NO_WARNINGS // will make the code invalid for next
// MSVC compiler versions
#ifdef _WIN32
#define _WINSOCK_DEPRECATED_NO_WARNINGS

#include <winsock2.h>
#define bzero(b, len) \
(memset((b), '\0', (len)), (void)0) /**< BSD name not in windows */
#define read(a, b, c) recv(a, b, c, 0) /**< map BSD name to Winsock */
#define write(a, b, c) send(a, b, c, 0) /**< map BSD name to Winsock */
#define close closesocket /**< map BSD name to Winsock */
#else // if not windows platform
#define bzero(b, len) (memset((b), '\0', (len)), (void)0)
#define read(a, b, c) recv(a, b, c, 0)
#define write(a, b, c) send(a, b, c, 0)
#define close closesocket
#else
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
#include <unistd.h>
#endif

#define MAX 80 /**< max. characters per message */
#define PORT 8080 /**< port number to connect to */
#define SA struct sockaddr /**< shortname for sockaddr */
#define MAX 80
#define PORT 8080
#define SA struct sockaddr

/**
* Continuous loop to send and receive over the socket.
* Exits when "exit" is sent from commandline.
* @param sockfd socket handle number
*/
void func(int sockfd)
{
char buff[MAX];
Expand All @@ -60,31 +47,25 @@ void func(int sockfd)
}

#ifdef _WIN32
/** Cleanup function will be automatically called on program exit */
void cleanup() { WSACleanup(); }
#endif

/**
* @brief Driver code
*/
int main()
{
#ifdef _WIN32
// when using winsock2.h, startup required
WSADATA wsData;
if (WSAStartup(MAKEWORD(2, 2), &wsData) != 0)
{
perror("WSA Startup error: \n");
return 0;
}

atexit(cleanup); // register at-exit function
atexit(cleanup);
#endif

int sockfd, connfd;
struct sockaddr_in servaddr, cli;

// socket create and verification
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1)
{
Expand All @@ -97,12 +78,10 @@ int main()
}
bzero(&servaddr, sizeof(servaddr));

// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
servaddr.sin_port = htons(PORT);

// connect the client socket to server socket
if (connect(sockfd, (SA *)&servaddr, sizeof(servaddr)) != 0)
{
printf("connection with the server failed...\n");
Expand All @@ -113,10 +92,8 @@ int main()
printf("connected to the server..\n");
}

// function for chat
func(sockfd);

// close the socket
close(sockfd);
return 0;
}
Loading
Loading