Changeset 84:bce54ecb0aad in livinglogic.python.tipimaid

Show
Ignore:
Timestamp:
02/03/09 16:59:32 (10 years ago)
Author:
Nik Tautenhahn <nik@…>
Branch:
default
Message:

Added an option to switch server to netcat-compatible mode (i.e. don't respond to each line / part of a line with \"1\")

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • liaalh_server.py

    r81 r84  
    1010        return defaultint 
    1111 
    12 def run(port=40000): 
     12def run(port=40000, netcat_compatible=False): 
    1313    backlog = 5 
    1414    size = 8192 
     
    4747                    data = s.recv(size) 
    4848                    if data: 
    49                         s.send("1") # notify the sender that we got something DISABLE THIS IF WE USE NETCAT AS SENDER! 
     49                        if not netcat_compatible: 
     50                            s.send("1") # notify the sender that we got something DISABLE THIS IF WE USE NETCAT AS SENDER! 
    5051                        inputs[s] += data 
    5152                        pos = inputs[s].rfind("\n") 
     
    6566    import optparse 
    6667    p = optparse.OptionParser(usage="usage: %prog port") 
     68    p.add_option("-n", "--netcat-compatible", dest="netcat", action="store_true", help="If set, %prog switches to netcat-compatible mode. Otherwise %prog assumes that it talks to its own sender which has better recovery in case of a broken connection.\nDo NOT use this switch if you use liaalh_sender!", default=None) # TODO: Fix name 
    6769    (options, args) = p.parse_args() 
    6870    if len(args) != 1 or intify(args[0], None) is None: 
     
    7072        sys.stderr.flush() 
    7173        return 1 
    72     run(port=intify(args[0], 40000)) 
     74    run(port=intify(args[0], 40000), netcat_compatible=options.netcat) 
    7375 
    7476if __name__ == "__main__":