Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8848287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:23:25+00:00 2026-06-14T12:23:25+00:00

Im trying to write perl TCP server / python TCP client, and i have

  • 0

Im trying to write perl TCP server / python TCP client, and i have the such code now:

import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ("127.0.0.1", 9000)
sock.connect(server_address)

try:
    message = unicode('Test')
    sock.sendall(message)
    data = sock.recv(1024)
    print data
finally:
    sock.close()

And i have noticed, that my TCP server (written in perl) is getting message not after sendall(message), but after close(). Server is working like an echo server, and sends data to client after getting a message. And that causes deadlock, server never gets a message, client never gets a response. What could be a problem? What is going to happen during close(), that message comes to server?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:23:26+00:00Added an answer on June 14, 2026 at 12:23 pm

    I’m going to hazard a guess that this is due to the server’s implementation. There are many ways of writing an echo server:

    • receieve bytes in a loop (or async callback) until EOF; as the bytes are recieved (each loop iteration), echo them without any processing or buffering; when an EOF is found (the inbound stream is closed), close the outbound stream
    • read lines at a time (assume it is a text protocol), i.e. looking for CR / LF / EOF; when a line is found, return the line – when an EOF is found (the inbound stream is closed), close the outbound stream
    • read to an EOF; then return everything and close the outbound stream

    If the echo server uses the first approach, it will work as expected already – so we can discount that.

    For the second approach, you are sending text but no CR / LF, and you haven’t closed the stream from client to server (EOF), so the server will never reply to this request. So yes, it will deadlock.

    If it is the third approach, then again – unless you close the outbound stream, it will deadlock.

    From your answer, it looks like adding a \n “fixes” it. From that, I conclude that your echo-server is line-based. So two solutions, and a third that would work in any scenario:

    1. make the echo-server respond to raw data, rather than lines
    2. add an end-of-line marker
    3. close the outbound stream at the client, i.e. the client-to-server stream (many network APIs allow you to close the outbound and inbound streams separately)

    Additionally: ensure Nagle is disabled (often called NO_DELAY) – this will prevent the bytes sitting at the client for a while, waiting to be composed into a decent sized packet (this applies to 1 & 2, but not 3; having Nagle enabled would add a delay, but will not usually cause a deadlock).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to write a bare-bones ping scanner using Perl for internal
I am trying to write a simple IO::Socket connection in perl. However, I am
I am trying to write a Perl script using WWW-Mechanize. Here is my code:
I have been trying to write a perl script to get all of the
I am trying to write new XS module for Perl. I have tested by
I'm trying to write some code against libnotify, but the documentation for perl with
I'm trying to write some code in perl (specifically) to output sound (specifically, MP3s)
I'm trying to write more efficient code in my scripts and have been implementing
I'm trying to write a Perl CGI script to handle XML-RPC requests, in which
I'm trying to write a Perl script that will parse the output of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.