Skip to content

This project is a simple implementation of a client-server model using Python's socket module. The server is able to handle multiple clients at once.

Notifications You must be signed in to change notification settings

ranimeshehata/Socket-Programming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Socket-Programming in Python

This project is a simple implementation of a client-server model using Python's socket module. The server is able to handle multiple clients at once.

Connections

  • Persistent connection is made between server and each client
  • Each connection runs on a separate thread.
  • Each connection has a dynamic timeout set by server, timeout = max(5 seconds, 20 - current-number-of-connections)
  • Server itself has a timeout of 60 seconds of inactivity, meaning if server doesb't get any requests for continuous 60 seconds it will shut down

Requests

Clients can send:

  • GET requests to get a certain file from the server
  • POST requests to send a file to the server

Responses

The server can respond with:

  • 200 OK if the request was successful
  • 404 Not Found if the requested file was not found

For GET requests, the server will send the file requested by the client. For POST requests, the server will save the file sent by the client.

Files Supported

The server can handle the following file types:

  • .txt
  • .jpg
  • .png
  • .html

How to run Server

  1. Default port: 8080
    python3 server/server.py
    
  2. Commandline argument port
    python3 server/server.py 8089
    

How to send Requests

  1. Client which asks for request every time
    python3 client/client.py 
    
  2. Client which parses file to send requests to server
    python3 client/client_parser.py hostname port
    
    Or use defaults, localhost and 8080:
    python3 client/client_parser.py
    

Testing

  1. Bonus Test Cases
    http://localhost:8080/server/testServer.txt
    
    http://localhost:8080/server/photoServer.jpg
    
    http://localhost:8080/server/welcome.html
    
  2. client.py tests
    GET server/testServer.txt
    
    POST client/testClient.txt
    
    GET server/photoServer.jpg
    
    POST client/photoClient.jpg
    
    GET server/welcome.html
    

Notes

index.html was changed because browsers load its favicon by default which leads to delay, so it was changed to welcome.html to avoid confusion.

Finally ... Welcome to our Server!

About

This project is a simple implementation of a client-server model using Python's socket module. The server is able to handle multiple clients at once.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published