Difficulty in execution

Asked

Viewed 25 times

2

I’m doing a show Served in Socket Python using interface Tkinter, cannot exchange script information, to enter into the Tkinter. when I run both of them importing the socket I have no way to execute the rest of the code Tkinter.. and when I execute code Tkinter, the socket server is already closed. so I cannot exchange information between both.

Tkinter code

import socket

import tkinter

n_client=0

root = tkinter.Tk()

root.geometry('200x200+600+200')

root['bg']='black'

import serv.py

list_clientes = tkinter.Listbox(root, width=25, height=5)

lb1= tkinter.Label(root, text='Welcome to Server')

lb1['fg'] = 'green'

lb1['bg'] = 'black'

lb2= tkinter.Label(root, text='List of Client')

lb2['fg'] = 'green'

lb2['bg'] = 'black'

lb3= tkinter.Label(root, text='Numbers of connections: %i' %n_client)

lb3['bg'] = 'black'
if n_client  > 0:
    lb3['fg'] = 'green'
if n_client  < 1:
    lb3['fg'] = 'red'
lb4= tkinter.Label(root, text='Server:')
lb4['fg'] = 'green'
lb4['bg'] = 'black'
'''if serv is bind():
    lb4['text']= 'Server: On'
else:
    lb4['text']= 'Server: Off'
'''
bt1 = tkinter.Button(root, text='Send message to client')

lb1.pack()
bt1.pack()
lb2.pack()
list_clientes.pack()
lb3.pack()
lb4.pack()

root.mainloop()

Code served

import socket

def socket_serv():

    host = ''

    port = 5000

    serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    serv.bind((host, port))

    serv.listen(1)

    while True:
        connect, cliente = serv.accept()
        print('Concetado por', cliente)
        while True:
            dados = connect.recv(1024)
            if not dados:
                break
            print(cliente, dados)
    serv.close()
    print('Finalizando conexao do cliente', cliente)
    return cliente
socket_serv()
print(socket_serv())
  • Identation is extremely important in Python you should start by editing your question and providing your code with proper formatting

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.