116

S is a server program: let's say it's an HTTP server, so it'll use the well-known port number for HTTP, which is 80. I run it on a host with IP address 10.0.0.4, so it will listen for connections on 10.0.0.4:80 (because that's where everyone will expect to find it). Inside S, I'm going to create a socket and bind it to that address: now, the OS knows that ...


49

Think of your machine as an apartment building: A port is an apartment number. A socket is the door of an apartment. An IP address is the street address of the building.


45

A port is part of the address in the TCP and UDP protocols. It is used to help the OS identify which application should get the data that is received. An OS has to support ports to support TCP and UDP because ports are an intrinsic part of TCP and UDP. A socket is part of the interface the OS presents to applications to allow them to send and receive ...


34

Well at the risk of sounding slightly cheesy: Ideas are timeless. By this I mean that the notion of a depth first search is goodness knows how old, but still totally relevant. Likewise, things that aren't totally platform and technology dependent tend to have a longer lifespan. If you learn things like Algorithms Data structures Paradigms and Concepts ...


29

... why would I rearrange the bytes ... when I already know that both, server and client run on little endian? Thats just unnecessary work to do. It's only unnecessary if you can guarantee your code will always run on little-endian architectures. If you intend for it to have a long life, it's worth the extra effort to avoid disturbing well-proven code a ...


26

Socket programming (at least as the term is normally used) is programming to one specific network API. Sockets support IP-based protocols (primarily TCP and UDP)1. Network programming can be done using various other APIs. Windows has a number of protocol-independent APIs such as the WNet* and Net* functions. Older versions of Windows also used NetBIOS/...


23

An open TCP connection is a logical state. It does not imply that that data is always being sent back and forth. After the initial three-way handshake you've entered into the "connected" state. You're in that state until either a 3-way disconnect occurs or a keep-alive fails. During the lifetime of the connection, resources from the underlying "physical" ...


23

The UDP protocol does not guarantee that messages are delivered in order or delivered at all, but it does ensure that those messages which do get delivered are complete and unchanged by automatically including a 16-bit checksum. That means adding another 16-bit checksum on the application layer is usually redundant. ...usually.... First, with IPv4 (not ...


20

IP addresses are a 32 bit integer which we typically express as four octets for human purposes. You could get the number of addresses in a range by turning both into their 32 bit integer representations and subtracting.


16

The old netchan was too intricate. The problem is to find a way to provide Go channel semantics on top of network hardware and software that, as always, finds a way to defeat all attempts at clean design. I will continue to ponder. -rob new netchan


14

I think Windows required applications to poll for IO until NT and Windows 95. Modern general purpose operating systems have pretty much eliminated the need for polling. When your application requests to read from a socket, the read function has to make a call to operating system kernel. The OS puts the calling thread into a suspended state. As network ...


14

This scenario of "nuclear apocalypse by inadvertence" would require some inordinate incompetence at some point. Namely, we can imagine a buggy router which mixes some packets together, and sends the wrong packet to the wrong destination. And then, inexplicably, the military system which receives the packet which, by a stroke of bad luck, contains what that ...


14

You could call it an address generically, or a socket address. From Wikipedia, "A socket address is the combination of an IP address and a port number."


13

Theoretically, this depends on the specifics of the OS and network hardware. In practice, mainstream OSes and hardware use a push model based on interrupts for interaction between the hardware and the OS (and all the software controlled by the OS). Basically, an interrupt is a very, very low-level mechanism through which peripheral hardware can signal the ...


12

UDP packets are not guaranteed to arrive in order. You should use TCP for this.


12

UDP does provide a checksum, however. The UDP checksum is only 16 bits. That means a 1 in 65536 chance of a corrupt packet passing the checksum. in UDP over IPv4 the checksum is optional, so a sender could theoretically end up sending a packet without a checksum. The checksum covers the IP/port information as well as the data. While this is useful in ...


12

Depends on if you're talking about peer-to-peer, client/server with the users running the server, or client/server with a data center running the server. Only in the latter-most case is the internet really fast and reliable. Your users' computers are not guaranteed to be fast, and certainly won't be reliable. UDP allows you greater control over the sort of ...


11

Request-response vs. message pushing Some architectures and protocols were designed for request-response type of communication. In HTTP, the client asks the server to GET, POST, DELETE, HEAD etc. something, and the server responds (or fails to respond). In POP3, the server role is limited to answer the requests, nothing more. Some others are designed in a ...


11

You won't be able to get an accurate count without any information about whether the range crosses subnet boundaries and what those subnets are. For example, 10.10.7.0 - 10.10.8.255 is a contiguous range of 512 addresses in the context of a /16. If that range covers two /24 blocks, the count is 508 because each block has a network address and a broadcast ...


11

If I already know the MAC address of the computer I want to connect to, is it possible to directly connect to it? Is there an example of this? You can connect at a low level and send packets to other machines on the same local network, but it'd be difficult to know what to put in those packets without knowing more about the protocols in upper layers. For ...


10

You should look at broadcasting. This is technique of sending your packets to all devices (IP's) in a subnet. It would look something like that: Android 192.168.0.101: Send message packet to broadcast address 192.168.0.254 PC 192.168.0.110: Reply to 192.168.0.101's broadcast message Android now knows PC's IP address and can communicate directly It's really ...


10

TLDR: The major drawback you might notice when multiplexing multiple channels on top of TCP (if you do it right) is an increased latency because of head-of-line blocking between the channels. Corollary: If you don't care about latency you should be fine. On the other hand using a single TCP connection “means less competition with other flows and longer-...


9

I think it is definitely not OK to synchornize the clock in the system. User does not expect you to touch the system settings and many systems won't even let you to. All you need is to have a correlation to convert timestamp from one side's clock to the other side's clock. On the other hand you need this correlation to be rather precise, say at least to a ...


9

I think your confusion is between the technical term "client" (as in client-server) and the business term "client" (as in, a paying customer). Multi-tenancy usually implies a server serving multiple business clients, each with their own separated environment, using shared hardware and software. For instance, I have several Wordpress blogs running on a ...


8

OK, I am not a Ethernet hardware engineer, but I think I can take a stab at your question. When you write code to listen from a port, the following happens: Your application code blocks/sleeps/"selects"/polls until the OS signals that a packet has arrived (with an some bits in the IP header indicating that packet is associated with that particular "port" ...


8

A computer has an IP address that identifies it as a separate entity on the network. We add an additional number to that to allow us to differentiate between connections to that computer. This is the port number. On the OS side of the connection you need buffers, connection state, etc. This logical object is the socket.


8

No, TCP will time out and request that a packet be re-sent, but there's no guaranteed transit time. TCP (typically) relies on IP, which can dynamically route packets, so there's no way to estimate how long it will/should take.


8

Your co-worker is totally wrong about the relationship between timeouts and user experience. Sure, the user would like a response within a second, but they want a successful response. Changing the timeout to a second doesn't help with that. I'd rather have an application that gives me what I want within three seconds than one that tells me within a second ...


7

However, the purpose of this is not to be a package manager, but instead a standard to follow when you want to implement a system that silently, automatically updates your software in the background. I'll look through apt and rpm! The problem is that what you want to do is building a package manager whether you like it or not. Your current proposed ...


7

FTP is a specific type of transfer system and is defined by a standards document (RFC 959). Unless you plan on implementing RFC 959, your file transfer system won't be FTP and shouldn't be on port 21. In fact, anything up to and including port 1023 is reserved for those types of well-known protocols. Ports 1024 and above are technically fair game for custom ...


Only top voted, non community-wiki answers of a minimum length are eligible