Answer the question
In order to leave comments, you need to log in
Can't solve input problem?
the problem is the following - I need the recv function to print the received message while the sender is waiting for input()
import socket
import threading
import json
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
with open('config.json', 'r') as file:
config = json.load(file)
for address in config['config']:
try:
sock.connect((address['address'][0], int(address['address'][1])))
except ConnectionRefusedError:
print('[LOG] - Ошибка подключения: проверьте подключение к интернету!')
else:
print('[LOG] - Вы успешно подключены!')
nickname = str(input('Ваш логин: '))
def recv():
while True:
data = sock.recv(1024)
if data:
print('\n' + data.decode('utf-8'))
def sender():
while True:
message = input('{}'.format(nickname) + ': ')
string = nickname + ': ' + message
sock.send(string.encode('utf-8'))
thread_rec = threading.Thread(target=recv)
thread_sender = threading.Thread(target=sender)
thread_rec.start()
thread_sender.start()
Answer the question
In order to leave comments, you need to log in
Everything turned out to be much easier! I selected all the files in folder 1, copied to folder 2 with a replacement, all the replaced files were selected after copying, cut and pasted into folder 3. Unprocessed files remained in folder 2!
Thanks everyone for the options!
Write a batch script in which you go through the FOR loop through all source files, checking for the non-existence of a file with the same name in the target folder and, if it does not exist, writing its name to the log file .
Done in one line.
I solved the issue like this:
For the solution, libraries are needed:
import asyncio
from prompt_toolkit import PromptSession
from prompt_toolkit.patch_stdout import patch_stdout
def recv():
while True:
data = sock.recv(1024)
if data:
print('\n' + data.decode('utf-8'))
async def sender():
session = PromptSession()
while True:
try:
with patch_stdout():
message = await session.prompt_async('{}'.format(nickname) + ': ')
string = nickname + ': ' + message
sock.send(string.encode('utf-8'))
except socket.error:
pass
thread_reciev = threading.Thread(target=recv, name="reciev_message")
thread_reciev.start()
asyncio.get_event_loop().run_until_complete(sender())
It is necessary that the string be of the following format: nickname of the sender + message of the sender, but when sending a message, the second user, after receiving the message, has a blank input line, how to solve this?
but when sending a messageand solder what happens there when sending, and what happens when receiving, and what does not happen to others and should not happen to you
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question