S
S
Surv168932020-02-15 22:44:30
Windows
Surv16893, 2020-02-15 22:44:30

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()
5e48487fbad49585529747.png

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

6 answer(s)
S
seostat, 2019-06-12
@seostat

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!

M
Moskus, 2019-06-12
@Moskus

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.

O
Otrivin, 2019-06-12
@Otrivin

Or take the Beyond Compare utility and compare folders with it

H
hint000, 2019-06-12
@hint000

Far manager -> F11 -> Advanced compare

S
Surv16893, 2020-02-19
@Surv16893

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())

D
Dimonchik, 2020-02-16
@dimonchik2013

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?

rewrite pliz for stupid
1) Sender console - the string is entered like this
2) receiver console - the string is obtained like this, and like this, but it should be like this
but when sending a message
and 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 question

Ask a Question

731 491 924 answers to any question