I have a basic socket server connection running with the general:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((hostHost, hostPort))
s.listen(10)
conn, addr = s.accept()
But whenever I try to call a
print(conn.send("Hello World"))
it returns an error:
NameError: global name 'conn' is not defined
I don't understand why this happens, can someone explain please? (I did this in a Tkinter window but I removed that code to simplify this).
NB: I have imported all the correct libraries, and if I change it to s.send, then the same error occurs.. I called the send() in another function:
def send_Button():
myMsg = "ME: " + text.get()
msg = text.get()
conn.send(msg)
textBox.insert(END, myMsg + "\n")
textEntry.delete(0, END)
textBox.yview_pickplace("end")
Thank you.