简体   繁体   中英

Python view of data sending over ethernet using socket

my question is about sending data via Ethernet using Python and Socket. I've just created a socket on Python side, I think the code is just simple and understandable. In this way I'd like just send data outside the computer.

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 'tcp')
host = socket.gethostname() 
port = 12345  # Example of a port
s.connect((host, port))  # set server connection((ip_server, port_server))
s.send("Data to send")
print s.recv(1024)  # receive data form the socket; argument is a bufsize
s.close

And if I create the socket right above, then the send data go via the port outside? Is it enough to for data to go out via the port? Using some sniffer programs I should see the data in some way?

Unfortunately it doesn't work. I have such a problem:

return getattr(self._sock,name)(*args) socket.error: [Errno 10061] and the comment is : can't set the connection because the destination computer refuses it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM