0

I have read contradictory definitions of what a socket comprise of (mainly in this question).

The first definition is that a socket comprise of the following:

{Source IP Address, Source Port Number}

The second definition is that a socket comprise of the following:

{Source IP Address, Source Port Number, Destination IP Address, Destination Port Number}

Is there an official document or something that states what the correct definition is?

Also, is the Transport protocol included in the socket?

Community
  • 1
  • 1
John
  • 1,049
  • 1
  • 14
  • 34

2 Answers2

1

If you look at the RFCs, e.g. RFC 193, TRANSMISSION CONTROL PROTOCOL, you will see the definition:

Multiplexing:

To allow for many processes within a single Host to use TCP communication facilities simultaneously, the TCP provides a set of addresses or ports within each host. Concatenated with the network and host addresses from the internet communication layer, this forms a socket. A pair of sockets uniquely identifies each connection. That is, a socket may be simultaneously used in multiple connections.

Ron Maupin
  • 6,180
  • 4
  • 29
  • 36
  • Is the Transport protocol considered a part of the socket? for example, are these two sockets considered valid or should I remove the Transport protocol from them?: **{TCP, 192.168.1.134, 1234}**, **{UDP, 192.168.1.21, 5678}**. – John Jun 28 '16 at 17:48
  • Sockets are per transport protocol. TCP port 80 is not the same as UDP port 80. Some transport protocols use different addressing than ports, and some have no addressing in the transport layer. Each transport protocol is independent of every other transport protocol. – Ron Maupin Jun 28 '16 at 17:51
  • If I want to say that I have a TCP socket with an IP of 192.168.1.134 and a port of 1234, can I represent this fact in the following way: **{TCP, 192.168.1.134, 1234}**? – John Jun 28 '16 at 18:00
  • That depends on the context. You will need to discover this for whichever programming language and/or library you are using. – Ron Maupin Jun 28 '16 at 18:03
  • No I meant if I want to represent the socket on paper, is this a valid way to write it, or there isn't really a convention on how to write it? – John Jun 28 '16 at 18:08
  • Many people use a colon to separate the address and the port, e.g. `192.168.1.134:1234` because that is how you see it in a URI. It's a bit different with IPv6 since the words are separated with colons, so the address is enclosed in square brackets, first, e.g. `[2001:db8::1234:5678:90ab:cdef]:1234`. I suppose you can represent it any way that makes sense to you. – Ron Maupin Jun 28 '16 at 18:14
1

The first definition applies to an unconnected TCP or UDP socket.

The second definition applies to a connected TCP or UDP socket.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • *"The first definition applies to an unconnected UDP socket"* Do you mean unconnected TCP socket? – John Jun 28 '16 at 18:26
  • I mean both actually. – user207421 Jun 28 '16 at 18:35
  • I didn't know you can have a connected UDP socket! I will check this out. – John Jun 28 '16 at 18:38
  • Technically, the definitions also need to include the protocol, since a UDP socket is different than a TCP socket, and on some platforms (Windows) it is possible to have different sockets using the same IP/Port pairs at the same time as long as their protocols are different. – Remy Lebeau Jun 28 '16 at 21:32