https://github.com/ranimeshehata/socket-programming
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.
https://github.com/ranimeshehata/socket-programming
client-server get-post-method networks python-socket socket-programming timeout
Last synced: 6 months ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/ranimeshehata/socket-programming
- Owner: ranimeshehata
- Created: 2024-11-01T19:30:10.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-11T21:17:29.000Z (about 1 year ago)
- Last Synced: 2025-02-09T00:52:59.678Z (11 months ago)
- Topics: client-server, get-post-method, networks, python-socket, socket-programming, timeout
- Language: Python
- Homepage:
- Size: 1.06 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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!
