Skip to content

divya2703/Client-Server-Arch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

Client-Server-Architecture

Overview

Using socket programming API in C, I have created a server capable of establishing connection with multiple clients and then implemented Stop-and-Wait based data link layer level logical channel between server and client to provide error detection functionality for the recieved message using Cyclic Redundancy Code. This was done as a part of Computer Networks Lab assignment in semester 6 @ IIT Guwahati under CSE dept with 2 other team members.

Theoretical Background

Socket programming is used to form a connection between two nodes, one acts as a server which listens to the request made by the other node known as client.

Stages in setting up Server

This involves 4 steps,

  • Socket Creation socket creation using socket(domain, type, protocol) api, which takes 3 arguments and returns an int (socket descriptor) for refering the created socket. If returned value is 0 means the socket creation process failed.
  1. int: communication domain, AF_INET for IPV4 protocol and AF_INET6 for IPV6 protocol
  2. int: SOCK_STREAM for TCP type connection and SOCK_DGRAM for UDP connection
  3. int: protocol, which is 0 for IP
  • Setsockopt
int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);

This step is an optional step which could be used to manipulate the options referred by socket descriptor. Can be used to allow server to have multiple parallel client connection. It can also be used to allow address reuse.

  • Bind
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);

bind helps to bind the socket to the address provided in the second argument we bind the server to the localhost, hence we use INADDR_ANY to specify the IP address.

  • Listen
int listen(int sockfd, int backlog);

Listen allows to set the server to listen for incoming request from client, the backlog argument is used to define the maximum length upto which pending connection can get queued up.

  • Accept
int new_socket= accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);

It extracts the first connection request on the queue of pending connections for the listening socket, sockfd, creates a new connected socket, and returns a new file descriptor referring to that socket. At this point, connection is established between client and server, and they are ready to transfer data.

Stages in setting up Client

There are 2 steps,

  • Socket creation - same as socket creation for server

  • Connect

int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);

The connect() system call connects the socket referred to by the file descriptor sockfd to the address specified by addr. Server’s address and port is specified in addr.

Code Details

server.c

client.c

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages