avatar Bite 334. Simple TCP client

Your job is to write a simple TCP/IP client which will contact a server and exchange data:

- The server is listening on a specific port and will send the client a fixed sized message when the client first connects.

- The server expects the client to reply with SHA-256 hash of the message the client received.

- The server will keep sending messages and expecting responses.

- The server will close connection at some point. Closing connection is indicated by server sending empty message b"".

Task

1. Create a client that will connect to the server using specific address and port. Address example: ("localhost", 4321)

2. The client will receive a fixed size message from the server.  

3. After each message is received, the client will answer with a confirmation message.

4. The confirmation message is 32 byte long SHA-256 hash generated from the received message.

5. The client continues to respond to messages until the server closes the connection.

6. The server may close the connection at any time, it's up to the client to handle this behavior (that is the client should not crash in such case).

Useful links

socket — Low-level networking interface

Socket Programming in Python (Guide)

Login and get coding
go back Intermediate level
Bitecoin 3X

17 out of 17 users completed this Bite.
Will you be the 18th person to crack this Bite?
Resolution time: ~43 min. (avg. submissions of 5-240 min.)

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help