Compare commits
No commits in common. "9243978b0eb8d08f669866e1d59bca695ece19c4" and "b6dca2e255abba8ccd4f6dc8b51746df77487b38" have entirely different histories.
9243978b0e
...
b6dca2e255
@ -82,7 +82,7 @@ def sendResponse(connection,data):
|
|||||||
|
|
||||||
senderThreadSleepMin = 0.0333
|
senderThreadSleepMin = 0.0333
|
||||||
senderThreadSleepMax = 1.0
|
senderThreadSleepMax = 1.0
|
||||||
senderThreadSleepIncr = 0.01
|
senderThreadSleepIncr = 0.05
|
||||||
|
|
||||||
class senderThread(threading.Thread):
|
class senderThread(threading.Thread):
|
||||||
def __init__(self,connectionThread):
|
def __init__(self,connectionThread):
|
||||||
@ -110,7 +110,7 @@ class senderThread(threading.Thread):
|
|||||||
with self.lock:
|
with self.lock:
|
||||||
sleepTime = self.sleep
|
sleepTime = self.sleep
|
||||||
|
|
||||||
#print(sleepTime)
|
print(sleepTime)
|
||||||
time.sleep(sleepTime)
|
time.sleep(sleepTime)
|
||||||
|
|
||||||
with self.lock:
|
with self.lock:
|
||||||
@ -153,11 +153,8 @@ class connectionThread(threading.Thread):
|
|||||||
print("thread closed: " +str(self.threadId)+ " (open: " +str(len(threads))+ ")")
|
print("thread closed: " +str(self.threadId)+ " (open: " +str(len(threads))+ ")")
|
||||||
self.closed = True
|
self.closed = True
|
||||||
|
|
||||||
def sendResponse(self,data,lock = True):
|
def sendResponse(self,data):
|
||||||
if lock == True:
|
with self.lock:
|
||||||
with self.lock:
|
|
||||||
self.senderThread.addToQueue([sendResponse,[self.connection,data],{}])
|
|
||||||
else:
|
|
||||||
self.senderThread.addToQueue([sendResponse,[self.connection,data],{}])
|
self.senderThread.addToQueue([sendResponse,[self.connection,data],{}])
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
moduleDepends([
|
|
||||||
p("[text server]","[api]","commands"),
|
|
||||||
])
|
|
||||||
|
|
||||||
global textSend
|
|
||||||
def textSend(self,command,args):
|
|
||||||
if len(args) < 2:
|
|
||||||
return ["error","nonfatal","syntax","Correct syntax: " +command+ ",<user>,<command>,[argument 1],[argument 2],..."]
|
|
||||||
|
|
||||||
user = args[0].lower()
|
|
||||||
if len(user) < 1:
|
|
||||||
return ["error","nonfatal","name_too_short","Needs to be at least 1 character in length."]
|
|
||||||
|
|
||||||
me = ""
|
|
||||||
with self.lock:
|
|
||||||
me = self.user
|
|
||||||
|
|
||||||
if not me:
|
|
||||||
return ["error","nonfatal","not_logged_in"]
|
|
||||||
|
|
||||||
with threadsLock:
|
|
||||||
for threadId in threads:
|
|
||||||
thread = threads[threadId]
|
|
||||||
with thread.lock:
|
|
||||||
if thread.user != user: continue
|
|
||||||
thread.sendResponse(textListToCommand(["send",me] + args[1:]).encode("utf-8"),lock = False)
|
|
||||||
|
|
||||||
return ["ok"]
|
|
||||||
textCommandAddHandler("send",textSend)
|
|
@ -33,6 +33,14 @@ def textOnRequest(event,self,requestLength):
|
|||||||
|
|
||||||
text = data.decode("utf-8")
|
text = data.decode("utf-8")
|
||||||
print(":".join(map(str,self.address))+ " > " +text)
|
print(":".join(map(str,self.address))+ " > " +text)
|
||||||
|
if text == "close":
|
||||||
|
with threadsLock:
|
||||||
|
global close
|
||||||
|
close = True
|
||||||
|
|
||||||
|
self.closeThread()
|
||||||
|
return True
|
||||||
|
|
||||||
response = textCommandRun(self,textCommandToList(text))
|
response = textCommandRun(self,textCommandToList(text))
|
||||||
print("response: " +textListToCommand(response))
|
print("response: " +textListToCommand(response))
|
||||||
self.sendResponse(textListToCommand(response).encode("utf-8"))
|
self.sendResponse(textListToCommand(response).encode("utf-8"))
|
||||||
|
@ -19,17 +19,6 @@ sp = pUp(s)
|
|||||||
|
|
||||||
# script start
|
# script start
|
||||||
import socket
|
import socket
|
||||||
import threading
|
|
||||||
|
|
||||||
class receiverThread(threading.Thread):
|
|
||||||
def __init__(self,connection):
|
|
||||||
threading.Thread.__init__(self)
|
|
||||||
self.connection = connection
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
while True:
|
|
||||||
response = getResponse(connection).decode("utf-8")
|
|
||||||
print("server: " +response)
|
|
||||||
|
|
||||||
def sendRequest(connection,data):
|
def sendRequest(connection,data):
|
||||||
connection.sendall(len(data).to_bytes(4,"big") + data)
|
connection.sendall(len(data).to_bytes(4,"big") + data)
|
||||||
@ -50,19 +39,23 @@ def main():
|
|||||||
global connection
|
global connection
|
||||||
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
connection.connect(("127.0.0.1",21779))
|
connection.connect(("127.0.0.1",21779))
|
||||||
thread = receiverThread(connection)
|
|
||||||
thread.start()
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
text = input()
|
text = input("data: ")
|
||||||
data = text.encode("utf-8")
|
data = text.encode("utf-8")
|
||||||
|
|
||||||
connection.settimeout(15)
|
|
||||||
sendRequest(connection,data)
|
sendRequest(connection,data)
|
||||||
connection.settimeout(None)
|
response = getResponse(connection).decode("utf-8")
|
||||||
|
print("server: " +response)
|
||||||
|
|
||||||
if text == "exit":
|
if text == "exit":
|
||||||
connection.close()
|
connection.close()
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if text == "close":
|
||||||
|
connection.close()
|
||||||
|
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
connection.connect(("127.0.0.1",21779))
|
||||||
|
connection.close()
|
||||||
|
break
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
Loading…
Reference in New Issue
Block a user