3
The program works properly, it creates a server for your user, the server opens smoothly. But when I use a client to access it, the following message appears in the server client:
Traceback (Most recent call last): File "C: Users JF Andrade Desktop Scriptspython Program011(Client). py", line 10, in sockobj.connect((serverHost, serverPort)) Connectionrefusederror: [Winerror 10061] No connection could be made because the destination machine actively refused them.
Could someone explain why this mistake? Thanks in advance.**
Server-side
from tkinter import *
from socket import *
import time
class AdminTools(object):
def __init__(self, main):
self.font = ("Verdana", "8", "bold")
self.Frame1 = Frame(main)
self.Frame1["bg"] = "LightBlue"
self.LabDiv2 = Label(main,text = "-----------------------------------------------------------")
self.LabDiv2["bg"] = "LightBlue"
self.LabDiv2.pack()
self.Lab1 = Label(main,text = "Bem-vindo ao Server Manager", fg = "Red", font = self.font)
self.Lab1["bg"] = "LightBlue"
self.Lab1.pack()
self.LabDiv1 = Label(main,text = "-----------------------------------------------------------")
self.LabDiv1["bg"] = "LightBlue"
self.LabDiv1.pack()
self.Lab2 = Label(main, text = "CRIAR NOVO SERVIDOR ", fg = "Green")
self.Lab2["bg"] = "LightBlue"
self.Lab2.pack()
self.Lab3 = Label(main, text = "HOST:", fg = "Black")
self.Lab3["bg"] = "LightBlue"
self.Lab3.pack()
self.Txt1 = Entry(main, bg = "LightGrey", fg = "Red")
self.Txt1.pack()
self.Del1 = Button(main, bg = "Red", text = "Del", command = self.ExcluirTexto, width = 6)
self.Del1.pack()
self.Lab4 = Label(main, text = "PORTA:", fg = "Black")
self.Lab4["bg"] = "LightBlue"
self.Lab4.pack()
self.Txt2 = Entry(main, fg = "Red", bg = "LightGrey")
self.Txt2.pack()
self.LabSpc1 = Label(main,text = "")
self.LabSpc1["bg"] = "LightBlue"
self.LabSpc1.pack()
self.Bt1 = Button(self.Frame1, text = "CRIAR SERVER", fg = "Black", bg = "Green", command = self.CriarServer, width = 12)
self.Bt1.pack()
self.Frame1.pack()
self.LabSpc1 = Label(self.Frame1, text = "", pady = 0)
self.LabSpc1["bg"] = "LightBlue"
self.LabSpc1.pack()
self.Bt2 = Button(self.Frame1, text = "FECHAR SERVER", bg = "RED", width = 12, command = self.FecharServer)
self.Bt2.pack()
def ExcluirTexto(self):
self.Txt1.delete(0, END)
def CriarServer(self):
Host = str(self.Txt1.get())
Port = int(self.Txt2.get())
sockobj = socket(AF_INET, SOCK_STREAM)
sockobj.bind((Host, Port))
sockobj.listen(5)
print("Servidor iniciado")
self.Lab3["text"] = "SERVIDOR INICIADO COM SUCESSO!"
self.Lab3["fg"] = "Blue"
AdminTools(main)
main.title("Server Manager v1.0")
main["bg"] = "LightBlue"
main = Tk()
main.geometry ("300x300")
main.mainloop()
Client side
from socket import *
serverHost = 'localhost'
serverPort = 45
sockobj = socket(AF_INET, SOCK_STREAM)
sockobj.connect((serverHost, serverPort))
print("Conexão estabelecida")
I’ll put in the post.
– user63295
Look but even so the server does not seem to be very well, take a look here... https://github.com/Miguel-Frazao/simple-chat , no Tkinter but is a multi-threading server (multiple clients) chat... You can run server Xtended that has more prints to see what’s happening
– Miguel
I am already working on a multi-thread server, this is a test server. But it has how to explain what happened on the test server?
– user63295
The code you set from the server gives me that main is not set. And you shouldn’t do an infinite loop for the server to run?
– Miguel
When I put the loop to keep it online and click create server it decides to crash.
– user63295
Take a look here at the answer http://answall.com/questions/166545/broken-pipe-com-sockets-em-python
– Miguel