Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/loyc12/miniserv42
https://github.com/loyc12/miniserv42
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/loyc12/miniserv42
- Owner: loyc12
- Created: 2024-08-13T16:46:12.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2024-08-13T16:56:10.000Z (3 months ago)
- Last Synced: 2024-08-13T20:12:46.765Z (3 months ago)
- Language: C
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Exam Question
This exam has 1 question, mini_serv:
- [Microshell.c](https://github.com/pasqualerossi/42-School-Exam-Rank-06/blob/main/mini_serv.c)
if you can make this code shorter whilst still readable, let me know !
# Expected File
mini_serv.c
# Allowed Functions
```
write, close and select
``````
socket, accept, listen, send, recv and bind
``````
strstr, strlen, strcpy, strcat, memset and bzero
``````
malloc, realloc, free, calloc, atoi and exit
``````
- sprintf
```# Subject Text
Write a program that will listen for client to connect on a certain port on 127.0.0.1 and will let clients to speak with each other. This program will take as first argument the port to bind to.
- If no argument is given, it should write in stderr "Wrong number of arguments" followed by a \n and exit with status 1
- If a System Calls returns an error before the program start accepting connection, it should write in stderr "Fatal error" followed by a \n and exit with status 1
- If you cant allocate memory it should write in stderr "Fatal error" followed by a \n and exit with status 1### Your Program
- Your program must be non-blocking but client can be lazy and if they don't read your message you must NOT disconnect them...
- Your program must not contains #define preproc
- Your program must only listen to 127.0.0.1The fd that you will receive will already be set to make 'recv' or 'send' to block if select hasn't be called before calling them, but will not block otherwise.
### When a client connect to the server:
- the client will be given an id. the first client will receive the id 0 and each new client will received the last client id + 1
- %d will be replace by this number
- a message is sent to all the client that was connected to the server: "server: client %d just arrived\n"### Clients must be able to send messages to your program.
- message will only be printable characters, no need to check
- a single message can contains multiple \n
- when the server receive a message, it must resend it to all the other client with "client %d: " before every line!### When a client disconnect from the server:
- a message is sent to all the client that was connected to the server: "server: client %d just left\n"
```
Memory or fd leaks are forbidden
```## Exam Practice
Practice the exam just like you would in the real exam - https://github.com/JCluzet/42_EXAM