Giter Site home page Giter Site logo

chat_server's Introduction

Chat server

This is a simple chat server i developed to better understand sockets.

It supports:

  • multiple clients
  • basic commands
  • custom port

to run the server:

./server port

to run the client("make client" to compile):

./client localhost port

UML Diagram

diagram

Commands

  • /quit : Quit chatroom.
  • /ping : Test.
  • /topic <message> : Set topic.
  • /nick <nick> : Change nick.
  • /msg <uid> : Send PM.
  • /list : Show active clients.
  • /help : Show commands.

Important Functions

socket()

int socket (int family, int type, int protocol);

creates a socket and returns an fd for it

bind()

struct sockaddr_in serv; /* IPv4 socket address structure */ int bind(sockfd, (struct sockaddr*) &serv, sizeof(serv))

bind the socket with an ip and port.

listen()

int listen(int sockfd, int backlog);

tell kernel to accept incoming connection requests to the socket.

accept()

int accept(int sockfd, struct sockaddr *cliaddr, socklen_t *addrlen);

accept a request and create a new socket for it.

Why thread over process to handle clients?

  • less memory usage.
  • easier IPC(inter process communication).

Useful links

https://www.cs.dartmouth.edu/~campbell/cs50/socketprogramming.html

more will be added

chat_server's People

Contributors

karadnz avatar

Stargazers

mustafa böyük avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.