localhost vs real ip address

When you access localhost, your /etc/hosts file will tell your computer not to look any further and redirects you to your own computer. When you access the local IP adress, your computer will ask the router to fetch the data, and your router will then point back to your computer.

How to know TCP connection is closed in net package?

That thread “Best way to reliably detect that a TCP connection is closed“, using net.Conn for ‘c‘ (also seen in utils/ping.go or locale-backend/server.go or many other instances): one := make([]byte, 1) c.SetReadDeadline(time.Now()) if _, err := c.Read(one); err == io.EOF { l.Printf(logger.LevelDebug, “%s detected closed LAN connection”, id) c.Close() c = nil } else { … Read more

WebSockets ping/pong, why not TCP keepalive?

The problems with TCP keepalive are: It is off by default. It operates at two-hour intervals by default, instead of on-demand as the Ping/Pong protocol provides. It operates between proxies rather than end to end. As pointed out by @DavidSchwartz, it operates between TCP stacks, not between the applications so therefore it doesn’t tell us … Read more

Assigning TCP/IP Ports for In-House Application Use

Ports 0-1023 are the Well Known Ports and are assigned by IANA. These should only be used for the assigned protocols on public networks. Ports 1024-65535 used to be called Registered Port Numbers (see rfc1700) but are now split into two areas (see rfc6335). Ports 1024-49151 are the User Ports and are the ones to … Read more

Size of empty UDP and TCP packet?

TCP: Size of Ethernet frame – 24 Bytes Size of IPv4 Header (without any options) – 20 bytes Size of TCP Header (without any options) – 20 Bytes Total size of an Ethernet Frame carrying an IP Packet with an empty TCP Segment – 24 + 20 + 20 = 64 bytes UDP: Size of … Read more

Setting TIME_WAIT TCP

A TCP connection is specified by the tuple (source IP, source port, destination IP, destination port). The reason why there is a TIME_WAIT state following session shutdown is because there may still be live packets out in the network on their way to you (or from you which may solicit a response of some sort). … Read more

Difference between TCP and UDP?

TCP is a connection oriented stream over an IP network. It guarantees that all sent packets will reach the destination in the correct order. This imply the use of acknowledgement packets sent back to the sender, and automatic retransmission, causing additional delays and a general less efficient transmission than UDP. UDP is a connection-less protocol. … Read more