python client and perl server: packing and unpacking bytes to send/receive
<p>python_client.py</p>

<pre><code>def send_one_message(sock, data):
    length = len(data)
    sock.sendall(struct.pack('!I', length))
    sock.sendall(data)
</code></pre>

<p>perl_server.pl</p>

<pre><code>sub ntohl {
    unpack("I", pack("N", $_[0]));
}

my $line = "";
$client_socket-&gt;recv($line, 4);
my $line_length = ntohl($line);
print "expected to receive $line_length bytes\n";

$client_socket-&gt;recv($line, $line_length);
print "$line\n";
</code></pre>

<p>I get this error:<br>
<code>Argument "\0\0\0C" isn't numeric in pack</code> in perl_server.pl</p>

<p>I dont think I am unpacking correctly in perl_server.pl</p>

<p>Any suggestions?</p>

<p>I've changed ntohl</p>

<pre><code>sub ntohl {
    unpack("I",  $_[0]);
}
</code></pre>

<p>and</p>

<pre><code>sock.sendall(struct.pack('I', length))
</code></pre>

python perl sockets