Logo
TGCATALOG
Catalog Collections Blog
Code on a Napkin - Python coding

Code on a Napkin - Python coding

Channel about programming in Python and other languages. Simple explanations and codes.

No ratings
311
25.10.2026
311
25.10.2026
No ratings
311
25.10.2026
Safe redirect via bot
О канале

Channel about programming in Python and other languages. Simple explanations and codes.

Подписчиков 2,345
Тематика Technology
Язык English
Ссылка t.me/napkincode

We also recommend

Kekaton AI | Voiceover and voice clone
Kekaton AI | Voiceover and voice clone
Bot

AI bot for text-to-speech and voice cloning in Telegram. Create audio using neural network quickly and easily.

Description

Resource for those interested in programming. Focus on Python, but covers other topics as well. Simple examples and breakdowns.

Latest posts

Code on a Napkin - Python coding
Code on a Napkin - Python coding
🔒Открыть пост
и посмотреть медиа
Знаете ли вы, почему TCP не сохраняет границы сообщений? Клиент отправляет hello и world двумя отдельными вызовами sendall(). На тестах кажется, что сервер сможет получить их двумя соответствующими вызовами recv(), но TCP такой связи не гарантирует. Он передает упорядоченный поток байтов, а каждый recv() возвращает доступную часть этого потока в пределах указанного размера. import socket server = socket.create_server(("127.0.0.1", 0)) client = socket.create_connection(server.getsockname()) connection, _ = server.accept() client.sendall(b"hello") client.sendall(b"world") client.shutdown(socket.SHUT_WR) data = b"" while chunk := connection.recv(1024): data += chunk print(data) # b'helloworld' Получатель видит десять байтов подряд. В потоке нет информации о том, были они отправлены как hello и world или разбиты между вызовами иначе. Кроме того, один большой send() может потребовать нескольких чтений, потому что recv(1024) возвращает максимум 1024 байта. Границы добавляет протокол приложения. Например, перед сообщением можно передать его длину: import socket import struct def receive_exactly(sock, size): data = b"" while len(data) < size: chunk = sock.recv(size - len(data)) if not chunk: raise EOFError("connection closed") data += chunk return data def receive_message(sock): size = struct.unpack("!I", receive_exactly(sock, 4))[0] return receive_exactly(sock, size) server = socket.create_server(("127.0.0.1", 0)) client = socket.create_connection(server.getsockname()) connection, _ = server.accept() for message in (b"hello", b"world"): client.sendall(struct.pack("!I", len(message)) + message) print(receive_message(connection)) print(receive_message(connection)) # b'hello' # b'world' Первые четыре байта задают длину следующего сообщения. receive_exactly() продолжает читать поток, пока не соберет нужное количество байтов, поэтому код работает при любом разбиении данных между вызовами recv(). TCP гарантирует порядок байтов, а границы сообщений определяет протокол приложения: длиной, разделителем или форматом с собственным фреймингом. Код на салфетке x Кусочки кода
Code on a Napkin - Python coding
FAQ

Open Code on a Napkin - Python coding in Telegram and press the Start button. No separate registration is required.

Yes. The service is designed to be straightforward: open the resource, follow the on-screen instructions and start using it.

No. You can use Code on a Napkin - Python coding directly in Telegram unless the resource description says otherwise.

Access depends on the resource. Check the current information in Telegram after opening Code on a Napkin - Python coding.

The exact features depend on the resource. Open Code on a Napkin - Python coding to see its current functions, content and access conditions.
Subscriber dynamics
+-0.5% last 30 days
Current
2,345
Month ago
2,356
Average growth
+0 / day
Updated
18 hours ago

Reviews for channel Code on a Napkin - Python coding

Log in to leave a review

Only registered users can share their opinion.

No reviews yet

Be the first to share your impression of this resource!

Similar resources

Loading
Switch to Light Theme
Home Catalog Collections Blog Login