
Write a TCP chat relay that listens on 127.0.0.1, accepts many clients at once, and forwards every message it receives to all the other connected clients. A single thread must stay responsive at all times, so the program is built around one I/O multiplexing loop and never blocks on a slow peer.
peer 0 connects, then peer 1 connectsExpected result
relay: peer 1 joinedFor your own tracking. Tests grade your code.
peer 0 sends "lgtm merge it\n"Expected result
peer 0 says: lgtm merge itpeer 0 sends "who broke main" then later "?\n"Expected result
peer 0 says: who broke main?Expected files
chat_relay.cAllowed functions
socketbindlistenacceptselectpollsignalsendrecvreadwriteclosesetsockoptfcntlhtonshtonlmalloccallocreallocfreememsetmemcpymemmovestrlenstrcpyatoisprintfsnprintfexit
v0.40: Create exercises. Challenge the community.
Meet Studio →Write a TCP chat relay that listens on 127.0.0.1, accepts many clients at once, and forwards every message it receives to all the other connected clients. A single thread must stay responsive at all times, so the program is built around one I/O multiplexing loop and never blocks on a slow peer.
peer 0 connects, then peer 1 connectsExpected result
relay: peer 1 joinedFor your own tracking. Tests grade your code.
peer 0 sends "lgtm merge it\n"Expected result
peer 0 says: lgtm merge itpeer 0 sends "who broke main" then later "?\n"Expected result
peer 0 says: who broke main?Expected files
chat_relay.cAllowed functions
socketbindlistenacceptselectpollsignalsendrecvreadwriteclosesetsockoptfcntlhtonshtonlmalloccallocreallocfreememsetmemcpymemmovestrlenstrcpyatoisprintfsnprintfexit
Run the tests to grade your code
Build your code, then check each test here. Open a result to inspect its output.