Skip to content

Commit

Permalink
support for Windows, added #quit command
Browse files Browse the repository at this point in the history
  • Loading branch information
sp9wpn committed Sep 21, 2024
1 parent 84281e9 commit 0c84826
Showing 1 changed file with 44 additions and 28 deletions.
72 changes: 44 additions & 28 deletions udp_client_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import time
import logging
from mopp import *
import config
import argparse
import sys
import select
import threading
import os

logging.basicConfig(level=logging.DEBUG, format='%(message)s', )

argparser = argparse.ArgumentParser(description='MOPP - IP/UDP console client')
argparser.add_argument('ip', help='Server IP address')
argparser.add_argument('server', help='Server IP or hostname')
argparser.add_argument('port', help='Server UDP port (default: 7373)', nargs='?', type=int, default=7373)

args=argparser.parse_args()
Expand All @@ -27,16 +26,55 @@

def transmit (data):
if len(data) > 0:
sock.sendto(data, (args.ip, args.port))
sock.sendto(data, (socket.gethostbyname(args.server), args.port))


def inputThread():
global speed

while True:
i = input().strip()
if i == '#quit':
transmit(mopp.mopp(speed, ':bye'))
print("Quitting...")
os._exit(0)
break

if i[0:1] == '#':
try:
_speed = int(i[1:])
if (_speed >= 5 and _speed <= 60):
speed = _speed
print("Speed set to %d wpm." % speed)
else:
print("Allowed speeds from 5 to 60 wpm.")

except:
pass

continue

for word in i.split(' '):
if word != '':
# print("Transmitting (%d wpm): %s" % (speed,word))
transmit(mopp.mopp(speed, word))



print("### MOPP - IP/UDP console client")
print("### Speed is set to %d wpm. To change, type: #<wpm>" % speed)
print("### To exit the program, use #quit")
print("")

# Login with hi
transmit(mopp.mopp(speed, 'hi'))


iThread = threading.Thread(target=inputThread)
iThread.daemon = True
iThread.start()


while KeyboardInterrupt:
try:
data_bytes, addr = sock.recvfrom(64)
Expand All @@ -49,33 +87,11 @@ def transmit (data):
pass

except (KeyboardInterrupt, SystemExit):
transmit(mopp.mopp(speed, ':bye'))
sock.close()
break
pass

except socket.timeout:
# time.sleep(0.2) # anti flood
pass

_i, _o, _e = select.select([sys.stdin], [], [], 1)
if (_i):
input = sys.stdin.readline().strip()

if input[0:1] == '#':
try:
_speed = int(input[1:])
if (_speed >= 5 and _speed <= 60):
speed = _speed
print("Speed set to %d wpm." % speed)
else:
print("Allowed speeds from 5 to 60 wpm.")

except:
pass

continue

for word in input.split(' '):
if word != '':
# print("Transmitting (%d wpm): %s" % (speed,word))
transmit(mopp.mopp(speed, word))

0 comments on commit 0c84826

Please sign in to comment.