Connecting two computers over ethernet (TCP socket python)

Hi,
I just wanted to share my method of point to point communication between two computers using a Jetson TK1 and linux desktop.

Connect Jetson TK1 and Linux PC using RJ45 cable

  1. Set ethernet IP address for both Jetson and PC
    For Jetson: sudo ip ad add 10.0.0.20/24 dev eth0
    For PC: sudo ip ad add 10.0.0.10/24 dev eno1

  2. Check the assigned IP address by using “ifconfig” command in terminal We can also ensure by using the command ==>
    nmap -p 80 10.0.0.20 (IP address of other device)
    which returns the following in case everything is successfully connected

Starting Nmap 7.80 ( https://nmap.org ) at 2020-11-24 11:54 IST
Nmap scan report for 10.0.0.20
Host is up (0.00064s latency).
PORT STATE SERVICE
80/tcp closed http
Nmap done: 1 IP address (1 host up) scanned in 0.04 seconds

Then do
ping 0.0.0.0(IP address of other device)

  1. Run socket_server.py in Jetson and socket_client.py in the LINUX PC .
    IN the Jetson: Connected by (‘10.0.0.10’,37240)
    IN the PC: Received b’Hello , world’
    NOTE: 10.0.0.20 is the IP address of Jetson and 10.0.0.10 is the IP address of PC
    The TCP connection is now established

socket_server.py

import socket
HOST = '10.0.0.20'  # Standard loopback interface address (localhost)
PORT = 65432        # Port to listen on (non-privileged ports are > 1023)

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen(5)
conn, addr = s.accept()
with conn:
    print('Connected by', addr)
    while True:
        data = conn.recv(1024)
        if not data:
            break
        conn.sendall(data)

socket_client.py

import socket
HOST = '10.0.0.20'  # The server's hostname or IP address
PORT = 65432        # The port used by the server

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((HOST, PORT))
    s.sendall(b'Hello, world')
    data = s.recv(1024)

print('Received', repr(data))

Cool! Thanks for your sharing to community!

Welcome!