init
This commit is contained in:
commit
82e264542f
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
/__pycache__/
|
||||||
|
/i-try/
|
||||||
|
/venv/
|
||||||
|
|
||||||
50
client.py
Normal file
50
client.py
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
import requests
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
|
||||||
|
class Client:
|
||||||
|
|
||||||
|
def __init__(self, username: str):
|
||||||
|
self.server = "95.165.158.131"
|
||||||
|
self.port = 80
|
||||||
|
self.username = username
|
||||||
|
|
||||||
|
self.talk_url = f"http://{self.server}:{self.port}/talk"
|
||||||
|
self.info_url = f"http://{self.server}:{self.port}/update"
|
||||||
|
|
||||||
|
|
||||||
|
def send_info(self):
|
||||||
|
|
||||||
|
while True:
|
||||||
|
user_input = input("You're message: ")
|
||||||
|
requests.post(self.talk_url, data={
|
||||||
|
"text": f'{self.username}: {user_input}'
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def update_info(self):
|
||||||
|
last_try = None
|
||||||
|
while True:
|
||||||
|
time.sleep(0.05)
|
||||||
|
r = requests.post(self.info_url)
|
||||||
|
if last_try == r.json():
|
||||||
|
continue
|
||||||
|
last_try = r.json()
|
||||||
|
os.system("cls")
|
||||||
|
for msg in last_try["status"]:
|
||||||
|
print(f"{msg}\n")
|
||||||
|
|
||||||
|
|
||||||
|
def __call__(self):
|
||||||
|
threads = [
|
||||||
|
threading.Thread(target=self.send_info),
|
||||||
|
threading.Thread(target=self.update_info)
|
||||||
|
]
|
||||||
|
for th in threads:
|
||||||
|
th.start()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
c = Client(input("Who are you? \t"))
|
||||||
|
c()
|
||||||
13
readme.MD
Normal file
13
readme.MD
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
how to run server on windows 10 / 11 in powershell
|
||||||
|
|
||||||
|
* python -m venv venv
|
||||||
|
* venv/scripts/Activate
|
||||||
|
* pip install -r reqs.txt
|
||||||
|
* sanic server.app -H 0.0.0.0 -p 80
|
||||||
|
|
||||||
|
how to run clear client
|
||||||
|
|
||||||
|
* python -m venv venv
|
||||||
|
* venv/scripts/Activate
|
||||||
|
* pip install -r reqs.txt
|
||||||
|
* python client.py
|
||||||
21
server.py
Normal file
21
server.py
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
from typing import Any, Coroutine
|
||||||
|
from sanic import Sanic, Request, response
|
||||||
|
from sanic.response import HTTPResponse
|
||||||
|
from sanic.server.websockets.impl import WebsocketImplProtocol
|
||||||
|
|
||||||
|
|
||||||
|
app = Sanic("app")
|
||||||
|
app.config.OAS = False
|
||||||
|
|
||||||
|
actual_messages = []
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/talk', methods=["GET", "POST"])
|
||||||
|
async def talking(request: Request) -> HTTPResponse:
|
||||||
|
actual_messages.append(request.form["text"])
|
||||||
|
return response.json({"status": "ok"})
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/update', methods=["GET", "POST"])
|
||||||
|
async def talking(request: Request) -> HTTPResponse:
|
||||||
|
return response.json({"status": actual_messages})
|
||||||
Loading…
Reference in New Issue
Block a user