Reputation: 1
I'm trying to send data from one software to another running on the same pc. The coding in the former s/w is done in python. I'm doing this:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto("msg,Hi!", ("127.0.0.1", 12345))
This works fine when I have internet access (AF_INET). However, this is just a sample code and I will need to include this piece in some other application where I will not have internet access and so AF_INET wouldn't work. Is there a possible replacement for this?
I've already tried AF_UNIX and AF_LOCAL but neither of them works. I need to use UDP.
Upvotes: 0
Views: 1388
Reputation: 3349
Of course, You do not need any Internet concepts while using Sockets. You can use an ad-hoc network to create a relaxed network and run a simple TCP or UDP socket script to transfer things you like.
You can infact use Multicasting or Broadcasting schemes to share data on different devices within the ad-hoc network.
Upvotes: 0
Reputation: 169
AF_INET has nothing to do with the INTERNET. It just means use IP based communication. You can do it on the same computer or across computers. 127.0.0.1 refers to local-host IP i.e. my own IP. Each unix/linux machine has the same local IP.
So yes this code will work without internet access.
Upvotes: 4