hola muchahos estoy tratando de crear una chat en local con python y tengo un problema con el codigo cliente
servidor tcp
import socket
host = "127.0.0.1"
port = 6666
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print ("Socket Created")
sock.bind((host, port))
print ("socket bind complete")
sock.listen(1)
print ("socket now listening")
while 1:
conn, addr = sock.accept()
print ('Connected with ') + addr[0] + ':' + str(addr[1])
sock.close()
output
socket create
socket bind complete
socket now listening
aparatenmente todo esta bien en la parte del servidor
cliente tcp
import socket
host = "127.0.0.1"
port = 6666
sock = socket.socket()
sock = socket.connect((host, port))
while true:
message = input("envia un mensaje")
sock.send(message.encode('utf-8'))
if message == "quit":
break
print("bye")
sock.close()
output
Traceback (most recent call last):
File "TcpClient.py", line 8, in <module>
sock = socket.connect((host, port))
AttributeError: module 'socket' has no attribute 'connect'