So Im working on a simple socket chat in python and I keep getting this error when i run this code in PyCharm. There are no visible errors in the editor. In the tutorial an int is used as port and string as ip but it doesnt work for me. It says
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Python27\lib\threading.py", line 810, in __bootstrap_inner
self.run()
File "C:\Python27\lib\threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: recv_loop() argument after * must be a sequence, not int.
Here is my code below
import socket
import threading
import os
connection = True
def send_loop(host, port2): # Thread 1!
s.connect((host, port2))
while connection:
msg = raw_input(":")
if msg == "/quit":
connection = False
s.send(msg.encode("ascii"))
s.send("Connection closed".encode("ascii"))
s.close()
return
def recv_loop(): # Thread 2!
ip = "192.168.1.7"
s.bind((ip, 12))
s.listen(1)
client, addr = s.accept()
print "connected with : " + addr
while connection:
var = client.recv(1024)
print var.decode("ascii")
print "Connection closed"
s.close()
return
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
############ User Input #############
port = int(raw_input("12/13:"))
if port == 12:
t = threading.Thread(target=recv_loop, args=(12))
elif port == 13:
t = threading.Thread(target=recv_loop(), args=(13))
else:
print "ERROR CODE 01"
t.start()
ip = raw_input("others ip:")
os.system("cls")
port2 = 0
if port == 12:
port2 = 13
elif port == 13:
port2 = 12
else:
print "ERROR CODE 2"
send_loop(ip, port2)