I have a chat client and but when I run it I get an error like this:
Traceback (most recent call last):
File "C:\Users\Public\Documents\Programming\Chat Client\Chat Client.py", line 21, in
<module>
s = socket.socket((socket.AF_INET, socket.SOCK_STREAM))
File "C:\Program Files\Python33\lib\socket.py", line 94, in __init__
_socket.socket.__init__(self, family, type, proto, fileno)
TypeError: an integer is required
I don't know what this means so can anyone please help me?
Here is my programs code:
# Import Modules
from tkinter import *
from socket import *
from threading import *
# Window Setup
root = Tk()
root.title('Chat Client')
root.state('zoomed')
# Chat Variables
global s
s = socket.socket((socket.AF_INET, socket.SOCK_STREAM))
s.connect((TARGET, DEFAULT_PORT))
enter = StringVar()
TARGET = s.gethostname()
DEFAULT_PORT = 45000
# Chat Message Box Setup
chat = Text(root, height=31, state=DISABLED)
entry = Entry(root, fg='blue', textvariable=enter, width=200)
scroll = Scrollbar(root)
chat['yscrollcommand'] = scroll.set
scroll['command'] = chat.yview
scroll.pack(side=RIGHT, fill=Y)
chat.pack(side=TOP, fill=X)
entry.pack(side=BOTTOM)
# Send Command
def send(event):
msg = enter.get()
chat['state'] = NORMAL
chat['fg'] = 'blue'
chat.insert(END, ('You: ' + msg + '\n'))
while 1:
s.sendall(msg)
chat['state'] = DISABLED
chat['fg'] = 'black'
enter.set('')
s.close()
entry.bind('<Return>', send)
def recieve():
s.bind((TARGET, DEFAULT_PORT))
s.listen(True)
conn, addr = s.accept()
while True:
data = conn.recv(1024)
chat['state'] = NORMAL
chat['fg'] = 'red'
chat.insert(END, ('Stranger: ' + data + '\n'))
thread.start(recieve, ())
thread.start(send, ())
root.mainloop()
So could anyone please help me with this as I don't know what I need to do with my code to fix this. Any Ideas?
Thanks In Advance!