即時通訊試圖瞭解套接字,我不能設法連接到IP,端口。 這是我拿到劇本:插座給我錯誤,當我嘗試連接-python
了Stian的插座測試工具
import socket
print "send request to website to check if sockets work right"
ip = raw_input("website ip: ")
port = raw_input("website port: ")
socket.connect(ip, port)
tosend = "this is a test"
currVal = 0
while currVal < 1:
socket.send(tosend)
print "1 sockets sent..."
currrVal += 1
print "Done sending sockets. This hopefully worked"
是什麼毛病Python代碼? 這是否只適用於ipv4或ipv6?還是它與兩個工作?
錯誤IM抵達:
C:\Users\Swipper\Documents\Python\sockets>sock.py
send request to website to check if sockets work right
website ip: 127.0.0.1
website port:
Traceback (most recent call last):
File "C:\Users\Swipper\Documents\Python\sockets\sock.py", line 8, in <modu
le>
socket.connect(ip, port)
AttributeError: 'module' object has no attribute 'connect'
希望有人知道答案。
PS:我使用python 2.7!
-stian
你的問題有點含糊。請包括您所得到的確切錯誤。 –