python, perl socket blocking difference when reading data from it? -
in perl, can do
socket(server, pf_inet, sock_stream, getprotobyname('tcp')); bind(server, $my_addr); listen(server, somaxconn); $client_address = accept(client, server); $line = <client>; # read until newline or eof print $line
when access via browser $line = <client>
return , print without blocking. if i'm trying same in python following
from socket import * host = "" port = 9000 address = (host, port) server = socket(af_inet, sock_stream) server.bind(address) server.listen(somaxconn) client, addr = server.accept() client_fd = client.makefile() data = client_fd.readlines() print data
client_fd.readlines()
blocking unless kill request in browser. there way around this? , why <client>
in perl not blocking?
your (updated) perl example reading one line client; python 1 reading all lines of input client, until socket closed. , client doesn't close socket, because it's hoping able http keepalive. should use readline
instead of readlines
read single line of input. or, if you're trying speak http, should use module made that.
Comments
Post a Comment