<br><div class="gmail_quote">On Thu, Feb 17, 2011 at 8:14 AM, Tim <span dir="ltr"><<a href="mailto:jtim.arnold@gmail.com">jtim.arnold@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi, I have an inetd service on freebsd that calls a program<br>
(daemon.py) with which I want the remote user to communicate.  I can<br>
call daemon.py from the command line on the host machine and it works<br>
fine.<br>
<br>
What I don't understand is how to make my remote client script<br>
actually communicate. If I'm understanding correctly, the code below<br>
just takes a message and sends it to inetd and writes the stdout from<br>
the process to the client.<br>
<br>
How can I modify the code to send a response back?   Here's the<br>
outline of what I want to do:<br>
(1) client sends the message to the server (client -> inetd -><br>
daemon.py),<br>
(2) client receives output back from the server,<br>
(3) client user responds to a question from the remote process<br>
(4) client continues to receive output back.<br>
<br>
where 2-3-4 happen as needed by the remote process. Cries out for a<br>
while loop doesn't it? I just don't know what to put in it. Currently<br>
I just have steps 1 and 2 working. Client sends one message and gets<br>
all output back. If server asks a question, processes deadlock with<br>
server waiting and client unable to respond.<br>
thanks,<br>
--Tim Arnold<br>
<br>
# imports, constants set<br>
#def line_buffer(sock):<br>
#    code to yield the string response in<br>
#    blocks of 1024 bytes<br>
<br>
def client(ip,port,message):<br>
    sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)<br>
    sock.connect((ip,port))<br>
    sock.send(message)<br>
    for line in line_buffer(sock):<br>
        print line<br>
    sock.close()<br>
<br>
if __name__ == '__main__':<br>
    message = ' '.join(sys.argv[1:])                                )<br>
    print 'working... %s %s' % (SERVER_IP,SERVER_PORT)<br>
    client(SERVER_IP,SERVER_PORT,message)<br>
    print 'done.'</blockquote><div><br>You could probably use strace/truss/ktrace to see what each process has done so far.<br><br>I wonder if your server process needs to flush its output when writing the prompt?<br>
<br>It might help us help you if you post the server code as well.  Also, the client code above doesn't appear to be complete...  posting more of that might help us help you as well.  Specifically: does line_buffer() know when to stop doing its thing?<br>
<br>BTW, when using unbuffered sockets, things are a bit complex - 3 writes in the server may appear as 1 recv or 4 recv's (or about any other #, including 3) in the client.  Usually you'll get 3, but that's not fully reliable.<br>
<br>Sometimes it helps to wrap up your socket in a python file, or to use something like <a href="http://stromberg.dnsalias.org/~strombrg/bufsock.html">http://stromberg.dnsalias.org/~strombrg/bufsock.html</a><br><br>HTH<br>
<br></div></div>