-1

I want to test my TCP communication program but my PC doesn't have any Ethernet Ports. What can I use to create a testing enviroment for my program?

  • 1
    Use addresses in the loopback block (`127.0.0.0/8` for IPv4 and `::1` for IPv6). TCP (layer-4) has nothing to do with ethernet (layer-2). – Ron Maupin Aug 04 '22 at 12:24
  • I can't set my IP address to a one that starts with 127 – Mert Özdemir Aug 04 '22 at 13:34
  • 2
    You already have that in your host. It is built into IP as the loopback. You cannot set an interface to such an address but you can use those addresses as if they were on internal interfaces. Simply sending anything to one of those addresses immediately loops back inside the host. This is used for testing, and it is the reason for loopback addresses. – Ron Maupin Aug 04 '22 at 13:41

1 Answers1

1

Any host running TCP/IP has a virtual loopback adapter that responds to IPv4 addresses 127.0.0.0/8 (often only 127.0.0.1 is used), or the IPv6 address ::1.

I'd recommend binding your listener to 0.0.0.0 (the unspecified address, representing any local address) and then connect using 127.0.0.1. For IPv6, use :: or ::0 for listening and connect to ::1.

TCP works in the exact same way as with a real address, so use ports as desired.

Zac67
  • 2,761
  • 1
  • 10
  • 21