The program works correctly, it creates a server for your user, the server opens without problems. But when I use a client to access it, the following message appears on the server client:
Traceback (most recent call last): File "C: \ Users \ JF Andrade \ Desktop \ ScriptsPython \ Program011 (Server_Server) .py", line 10, in sockobj.connect ((serverHost, serverPort)) ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused them.
Could it explain why this error? Thank you 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()
Customer Side
from socket import *
serverHost = 'localhost'
serverPort = 45
sockobj = socket(AF_INET, SOCK_STREAM)
sockobj.connect((serverHost, serverPort))
print("Conexão estabelecida")