How to send data between two Raspberry Pis in two separate houses using TCP












1















So I'm trying to figure out how to send string data between two Pi Zero W units. I want one of them to be with me and one of them to be with one of my friends in her house. I'm really confused as to how this would work. I found a bit of code that seemed to work for both units in my house but, after changing the IP Address to my friend's public IP and trying to use it at her house, nothing came through. I'm fairly new to using internet protocols so any help would be appreciated.



Send.py



import sys
from socket import socket, AF_INET, SOCK_DGRAM

SERVER_IP = ''
PORT_NUMBER = 5000
SIZE = 1024
print ("Test client sending packets to IP {0}, via port
{1}n".format(SERVER_IP,
PORT_NUMBER))

mySocket = socket( AF_INET, SOCK_DGRAM )

while True:
myMessage = input()
mySocket.sendto(myMessage.encode('utf-8'),(SERVER_IP,PORT_NUMBER))
sys.exit()


Receive.py



#!/usr/bin/env python3

from socket import socket, gethostbyname, AF_INET, SOCK_DGRAM
import sys
PORT_NUMBER = 5000
SIZE = 128

hostName = gethostbyname( '0.0.0.0' )

mySocket = socket( AF_INET, SOCK_DGRAM )
mySocket.bind( (hostName, PORT_NUMBER) )

print ("Test server listening on port {0}n".format(PORT_NUMBER))

while True:
(data,addr) = mySocket.recvfrom(SIZE)
print(data.decode('utf-8'))
sys.exit()









share|improve this question

























  • Did you do any port forwarding on your/your friend's router?

    – FamousJameous
    Nov 27 '18 at 23:18











  • You should probably learn TCP inside out before you try messing with UDP. It's much more complicated.

    – David Schwartz
    Nov 27 '18 at 23:22











  • @FamousJameous I did set up port forwarding on mine but not hers.

    – Charlie C
    Nov 27 '18 at 23:26











  • Your question asks about TCP but your code requests UDP sockets.

    – David Schwartz
    Nov 27 '18 at 23:29











  • @DavidSchwartz Like I said Im new to this stuff and I really dont know where I can go to research it

    – Charlie C
    Nov 27 '18 at 23:30
















1















So I'm trying to figure out how to send string data between two Pi Zero W units. I want one of them to be with me and one of them to be with one of my friends in her house. I'm really confused as to how this would work. I found a bit of code that seemed to work for both units in my house but, after changing the IP Address to my friend's public IP and trying to use it at her house, nothing came through. I'm fairly new to using internet protocols so any help would be appreciated.



Send.py



import sys
from socket import socket, AF_INET, SOCK_DGRAM

SERVER_IP = ''
PORT_NUMBER = 5000
SIZE = 1024
print ("Test client sending packets to IP {0}, via port
{1}n".format(SERVER_IP,
PORT_NUMBER))

mySocket = socket( AF_INET, SOCK_DGRAM )

while True:
myMessage = input()
mySocket.sendto(myMessage.encode('utf-8'),(SERVER_IP,PORT_NUMBER))
sys.exit()


Receive.py



#!/usr/bin/env python3

from socket import socket, gethostbyname, AF_INET, SOCK_DGRAM
import sys
PORT_NUMBER = 5000
SIZE = 128

hostName = gethostbyname( '0.0.0.0' )

mySocket = socket( AF_INET, SOCK_DGRAM )
mySocket.bind( (hostName, PORT_NUMBER) )

print ("Test server listening on port {0}n".format(PORT_NUMBER))

while True:
(data,addr) = mySocket.recvfrom(SIZE)
print(data.decode('utf-8'))
sys.exit()









share|improve this question

























  • Did you do any port forwarding on your/your friend's router?

    – FamousJameous
    Nov 27 '18 at 23:18











  • You should probably learn TCP inside out before you try messing with UDP. It's much more complicated.

    – David Schwartz
    Nov 27 '18 at 23:22











  • @FamousJameous I did set up port forwarding on mine but not hers.

    – Charlie C
    Nov 27 '18 at 23:26











  • Your question asks about TCP but your code requests UDP sockets.

    – David Schwartz
    Nov 27 '18 at 23:29











  • @DavidSchwartz Like I said Im new to this stuff and I really dont know where I can go to research it

    – Charlie C
    Nov 27 '18 at 23:30














1












1








1








So I'm trying to figure out how to send string data between two Pi Zero W units. I want one of them to be with me and one of them to be with one of my friends in her house. I'm really confused as to how this would work. I found a bit of code that seemed to work for both units in my house but, after changing the IP Address to my friend's public IP and trying to use it at her house, nothing came through. I'm fairly new to using internet protocols so any help would be appreciated.



Send.py



import sys
from socket import socket, AF_INET, SOCK_DGRAM

SERVER_IP = ''
PORT_NUMBER = 5000
SIZE = 1024
print ("Test client sending packets to IP {0}, via port
{1}n".format(SERVER_IP,
PORT_NUMBER))

mySocket = socket( AF_INET, SOCK_DGRAM )

while True:
myMessage = input()
mySocket.sendto(myMessage.encode('utf-8'),(SERVER_IP,PORT_NUMBER))
sys.exit()


Receive.py



#!/usr/bin/env python3

from socket import socket, gethostbyname, AF_INET, SOCK_DGRAM
import sys
PORT_NUMBER = 5000
SIZE = 128

hostName = gethostbyname( '0.0.0.0' )

mySocket = socket( AF_INET, SOCK_DGRAM )
mySocket.bind( (hostName, PORT_NUMBER) )

print ("Test server listening on port {0}n".format(PORT_NUMBER))

while True:
(data,addr) = mySocket.recvfrom(SIZE)
print(data.decode('utf-8'))
sys.exit()









share|improve this question
















So I'm trying to figure out how to send string data between two Pi Zero W units. I want one of them to be with me and one of them to be with one of my friends in her house. I'm really confused as to how this would work. I found a bit of code that seemed to work for both units in my house but, after changing the IP Address to my friend's public IP and trying to use it at her house, nothing came through. I'm fairly new to using internet protocols so any help would be appreciated.



Send.py



import sys
from socket import socket, AF_INET, SOCK_DGRAM

SERVER_IP = ''
PORT_NUMBER = 5000
SIZE = 1024
print ("Test client sending packets to IP {0}, via port
{1}n".format(SERVER_IP,
PORT_NUMBER))

mySocket = socket( AF_INET, SOCK_DGRAM )

while True:
myMessage = input()
mySocket.sendto(myMessage.encode('utf-8'),(SERVER_IP,PORT_NUMBER))
sys.exit()


Receive.py



#!/usr/bin/env python3

from socket import socket, gethostbyname, AF_INET, SOCK_DGRAM
import sys
PORT_NUMBER = 5000
SIZE = 128

hostName = gethostbyname( '0.0.0.0' )

mySocket = socket( AF_INET, SOCK_DGRAM )
mySocket.bind( (hostName, PORT_NUMBER) )

print ("Test server listening on port {0}n".format(PORT_NUMBER))

while True:
(data,addr) = mySocket.recvfrom(SIZE)
print(data.decode('utf-8'))
sys.exit()






python tcp wireless data-transfer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 28 '18 at 1:41









Pang

6,9531664103




6,9531664103










asked Nov 27 '18 at 23:13









Charlie CCharlie C

132




132













  • Did you do any port forwarding on your/your friend's router?

    – FamousJameous
    Nov 27 '18 at 23:18











  • You should probably learn TCP inside out before you try messing with UDP. It's much more complicated.

    – David Schwartz
    Nov 27 '18 at 23:22











  • @FamousJameous I did set up port forwarding on mine but not hers.

    – Charlie C
    Nov 27 '18 at 23:26











  • Your question asks about TCP but your code requests UDP sockets.

    – David Schwartz
    Nov 27 '18 at 23:29











  • @DavidSchwartz Like I said Im new to this stuff and I really dont know where I can go to research it

    – Charlie C
    Nov 27 '18 at 23:30



















  • Did you do any port forwarding on your/your friend's router?

    – FamousJameous
    Nov 27 '18 at 23:18











  • You should probably learn TCP inside out before you try messing with UDP. It's much more complicated.

    – David Schwartz
    Nov 27 '18 at 23:22











  • @FamousJameous I did set up port forwarding on mine but not hers.

    – Charlie C
    Nov 27 '18 at 23:26











  • Your question asks about TCP but your code requests UDP sockets.

    – David Schwartz
    Nov 27 '18 at 23:29











  • @DavidSchwartz Like I said Im new to this stuff and I really dont know where I can go to research it

    – Charlie C
    Nov 27 '18 at 23:30

















Did you do any port forwarding on your/your friend's router?

– FamousJameous
Nov 27 '18 at 23:18





Did you do any port forwarding on your/your friend's router?

– FamousJameous
Nov 27 '18 at 23:18













You should probably learn TCP inside out before you try messing with UDP. It's much more complicated.

– David Schwartz
Nov 27 '18 at 23:22





You should probably learn TCP inside out before you try messing with UDP. It's much more complicated.

– David Schwartz
Nov 27 '18 at 23:22













@FamousJameous I did set up port forwarding on mine but not hers.

– Charlie C
Nov 27 '18 at 23:26





@FamousJameous I did set up port forwarding on mine but not hers.

– Charlie C
Nov 27 '18 at 23:26













Your question asks about TCP but your code requests UDP sockets.

– David Schwartz
Nov 27 '18 at 23:29





Your question asks about TCP but your code requests UDP sockets.

– David Schwartz
Nov 27 '18 at 23:29













@DavidSchwartz Like I said Im new to this stuff and I really dont know where I can go to research it

– Charlie C
Nov 27 '18 at 23:30





@DavidSchwartz Like I said Im new to this stuff and I really dont know where I can go to research it

– Charlie C
Nov 27 '18 at 23:30












1 Answer
1






active

oldest

votes


















1














if you want to connect them together:




  1. RPI that listens to incoming TCP connections (Receive.py) has to have firewall port open on RPI (https://raspberrypi.stackexchange.com/questions/69123/how-to-open-a-port)

  2. there has to be port open on your home router that connects your RPI to the ISP

  3. your RPI cannot be behind provider's NAT network - sometimes, you can purchase a static IP address from your provider, that doesn't change or at least public IP address that dynamically changes in time.


You can check if you're behind NAT in router admin page, check if the IP that router got assigned from ISP is the same as your IP address that servers on the internet see. Do this query:



https://www.google.com/search?q=what+is+my+ip+address )



If they're same, you're not behind ISP's NAT and problem is not probably there. If the're different, you share IP's with other ISP's customers and you cannot run your own server app that will expose it's port to the internet.






share|improve this answer


























  • Thank you! So I am not under my ISP's NAT. I can see my public IP and it is the same as my routers. But my friends IP is under her ISP's NAT. So I'm guessing this way wont work. Is their anyway that I can send data between us that doesn't require us both to not be under our ISP's NATs? Or what are some ways that I could set this up?

    – Charlie C
    Nov 28 '18 at 4:41











  • You can run socket server that listens at your home and the friend's RPI will connect to yours, because you can initiate TCP stream from inside of NAT network with no problem.

    – nio
    Nov 28 '18 at 12:21











  • Ok thanks. Ill look into that. Again like I said, Im very new to this so thank you

    – Charlie C
    Nov 28 '18 at 14:54











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53509671%2fhow-to-send-data-between-two-raspberry-pis-in-two-separate-houses-using-tcp%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














if you want to connect them together:




  1. RPI that listens to incoming TCP connections (Receive.py) has to have firewall port open on RPI (https://raspberrypi.stackexchange.com/questions/69123/how-to-open-a-port)

  2. there has to be port open on your home router that connects your RPI to the ISP

  3. your RPI cannot be behind provider's NAT network - sometimes, you can purchase a static IP address from your provider, that doesn't change or at least public IP address that dynamically changes in time.


You can check if you're behind NAT in router admin page, check if the IP that router got assigned from ISP is the same as your IP address that servers on the internet see. Do this query:



https://www.google.com/search?q=what+is+my+ip+address )



If they're same, you're not behind ISP's NAT and problem is not probably there. If the're different, you share IP's with other ISP's customers and you cannot run your own server app that will expose it's port to the internet.






share|improve this answer


























  • Thank you! So I am not under my ISP's NAT. I can see my public IP and it is the same as my routers. But my friends IP is under her ISP's NAT. So I'm guessing this way wont work. Is their anyway that I can send data between us that doesn't require us both to not be under our ISP's NATs? Or what are some ways that I could set this up?

    – Charlie C
    Nov 28 '18 at 4:41











  • You can run socket server that listens at your home and the friend's RPI will connect to yours, because you can initiate TCP stream from inside of NAT network with no problem.

    – nio
    Nov 28 '18 at 12:21











  • Ok thanks. Ill look into that. Again like I said, Im very new to this so thank you

    – Charlie C
    Nov 28 '18 at 14:54
















1














if you want to connect them together:




  1. RPI that listens to incoming TCP connections (Receive.py) has to have firewall port open on RPI (https://raspberrypi.stackexchange.com/questions/69123/how-to-open-a-port)

  2. there has to be port open on your home router that connects your RPI to the ISP

  3. your RPI cannot be behind provider's NAT network - sometimes, you can purchase a static IP address from your provider, that doesn't change or at least public IP address that dynamically changes in time.


You can check if you're behind NAT in router admin page, check if the IP that router got assigned from ISP is the same as your IP address that servers on the internet see. Do this query:



https://www.google.com/search?q=what+is+my+ip+address )



If they're same, you're not behind ISP's NAT and problem is not probably there. If the're different, you share IP's with other ISP's customers and you cannot run your own server app that will expose it's port to the internet.






share|improve this answer


























  • Thank you! So I am not under my ISP's NAT. I can see my public IP and it is the same as my routers. But my friends IP is under her ISP's NAT. So I'm guessing this way wont work. Is their anyway that I can send data between us that doesn't require us both to not be under our ISP's NATs? Or what are some ways that I could set this up?

    – Charlie C
    Nov 28 '18 at 4:41











  • You can run socket server that listens at your home and the friend's RPI will connect to yours, because you can initiate TCP stream from inside of NAT network with no problem.

    – nio
    Nov 28 '18 at 12:21











  • Ok thanks. Ill look into that. Again like I said, Im very new to this so thank you

    – Charlie C
    Nov 28 '18 at 14:54














1












1








1







if you want to connect them together:




  1. RPI that listens to incoming TCP connections (Receive.py) has to have firewall port open on RPI (https://raspberrypi.stackexchange.com/questions/69123/how-to-open-a-port)

  2. there has to be port open on your home router that connects your RPI to the ISP

  3. your RPI cannot be behind provider's NAT network - sometimes, you can purchase a static IP address from your provider, that doesn't change or at least public IP address that dynamically changes in time.


You can check if you're behind NAT in router admin page, check if the IP that router got assigned from ISP is the same as your IP address that servers on the internet see. Do this query:



https://www.google.com/search?q=what+is+my+ip+address )



If they're same, you're not behind ISP's NAT and problem is not probably there. If the're different, you share IP's with other ISP's customers and you cannot run your own server app that will expose it's port to the internet.






share|improve this answer















if you want to connect them together:




  1. RPI that listens to incoming TCP connections (Receive.py) has to have firewall port open on RPI (https://raspberrypi.stackexchange.com/questions/69123/how-to-open-a-port)

  2. there has to be port open on your home router that connects your RPI to the ISP

  3. your RPI cannot be behind provider's NAT network - sometimes, you can purchase a static IP address from your provider, that doesn't change or at least public IP address that dynamically changes in time.


You can check if you're behind NAT in router admin page, check if the IP that router got assigned from ISP is the same as your IP address that servers on the internet see. Do this query:



https://www.google.com/search?q=what+is+my+ip+address )



If they're same, you're not behind ISP's NAT and problem is not probably there. If the're different, you share IP's with other ISP's customers and you cannot run your own server app that will expose it's port to the internet.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 28 '18 at 1:56

























answered Nov 28 '18 at 1:50









nionio

4,37821632




4,37821632













  • Thank you! So I am not under my ISP's NAT. I can see my public IP and it is the same as my routers. But my friends IP is under her ISP's NAT. So I'm guessing this way wont work. Is their anyway that I can send data between us that doesn't require us both to not be under our ISP's NATs? Or what are some ways that I could set this up?

    – Charlie C
    Nov 28 '18 at 4:41











  • You can run socket server that listens at your home and the friend's RPI will connect to yours, because you can initiate TCP stream from inside of NAT network with no problem.

    – nio
    Nov 28 '18 at 12:21











  • Ok thanks. Ill look into that. Again like I said, Im very new to this so thank you

    – Charlie C
    Nov 28 '18 at 14:54



















  • Thank you! So I am not under my ISP's NAT. I can see my public IP and it is the same as my routers. But my friends IP is under her ISP's NAT. So I'm guessing this way wont work. Is their anyway that I can send data between us that doesn't require us both to not be under our ISP's NATs? Or what are some ways that I could set this up?

    – Charlie C
    Nov 28 '18 at 4:41











  • You can run socket server that listens at your home and the friend's RPI will connect to yours, because you can initiate TCP stream from inside of NAT network with no problem.

    – nio
    Nov 28 '18 at 12:21











  • Ok thanks. Ill look into that. Again like I said, Im very new to this so thank you

    – Charlie C
    Nov 28 '18 at 14:54

















Thank you! So I am not under my ISP's NAT. I can see my public IP and it is the same as my routers. But my friends IP is under her ISP's NAT. So I'm guessing this way wont work. Is their anyway that I can send data between us that doesn't require us both to not be under our ISP's NATs? Or what are some ways that I could set this up?

– Charlie C
Nov 28 '18 at 4:41





Thank you! So I am not under my ISP's NAT. I can see my public IP and it is the same as my routers. But my friends IP is under her ISP's NAT. So I'm guessing this way wont work. Is their anyway that I can send data between us that doesn't require us both to not be under our ISP's NATs? Or what are some ways that I could set this up?

– Charlie C
Nov 28 '18 at 4:41













You can run socket server that listens at your home and the friend's RPI will connect to yours, because you can initiate TCP stream from inside of NAT network with no problem.

– nio
Nov 28 '18 at 12:21





You can run socket server that listens at your home and the friend's RPI will connect to yours, because you can initiate TCP stream from inside of NAT network with no problem.

– nio
Nov 28 '18 at 12:21













Ok thanks. Ill look into that. Again like I said, Im very new to this so thank you

– Charlie C
Nov 28 '18 at 14:54





Ok thanks. Ill look into that. Again like I said, Im very new to this so thank you

– Charlie C
Nov 28 '18 at 14:54




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53509671%2fhow-to-send-data-between-two-raspberry-pis-in-two-separate-houses-using-tcp%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks