Difficulty in running

2

I'm doing a program Served on Socket Python using interface Tkinter , I can not exchange information from the scripts, to enter into the Tkinter GUI. when I execute both 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 can not exchange information between them.

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

Served Code

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())
    
asked by anonymous 08.01.2018 / 19:53

0 answers