GithubHelp home page GithubHelp logo

client_server_project_uni's Introduction

Client_Server_Project_Uni

Socket Programming Chat Application

This is a simple chat application using socket programming in Python. It consists of a server and client that can communicate with each other.

Files

It contains the following files:

  • server.py - The server code
  • client1.py - The client code

Server

Key features:

  • Creates a socket and binds it to localhost and port 12345
  • Listens for incoming connections in a loop
  • For each client, creates a thread to handle sending and receiving of messages
  • Maintains a dictionary of client connections
  • Broadcasts messages from one client to all other connected clients
  • Closes client sockets gracefully on disconnect

Client

Key features:

  • Creates a socket and connects to the server
  • Sends messages to the server by taking user input
  • Receives messages from the server and prints them
  • Cleanly closes socket on exiting

Usage

To run the application:

  1. Start the server: python server.py

To start the server:

python server.py

This will start the server on localhost port 12345.

  1. Open another terminal and run the client: python client1.py

To start the client:

python client.py

This will connect the client to the running server.

Multiple clients can connect to the same server. Each client connection will be handled in a separate thread.

  1. Send messages from the client and observe the communication.
  2. Type 'exit' on the client to disconnect gracefully.

Server

The server has the following capabilities:

  • Accept connections from multiple clients
  • Receive and send messages to each connected client
  • Broadcast messages from one client to all others
  • Gracefully handle client disconnections

The main components are:

  • Socket creation and binding
  • Listening for connections in a loop
  • Spawning a thread per client to handle all communication
  • Cleaning up threads when clients disconnect

Client

The client can:

  • Connect to the server
  • Send messages to the server
  • Receive messages from the server
  • Gracefully handle disconnection

The key components are:

  • Socket creation and connection
  • Threads for sending and receiving messages
  • Clean shutdown on disconnect

Message Handling

Some of the key aspects of message handling are:

  • Prefixing messages with client name
  • Detecting client disconnects by empty recv
  • Broadcast by looping through all connected clients

Communication Logic

  • The server handles each client connection in a separate thread.
  • When a client sends a message, it is broadcast to all other clients.
  • The main threads handle sending and receiving messages independently.

This allows building a simple chat application using socket programming concepts.

Let me know if you would like me to explain or expand any part of the README!

This provides a basic template for building more complex chat applications.

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.