Skip to main content
64 votes

Why can't sockets be used to identify individuals instead of cookies?

A socket identifies a connection. Cookies are usually used to identify a user. If I open two browser tabs to SE.SE, I will have two connections and thus two sockets. But I want my settings to persist ...
Jörg W Mittag's user avatar
21 votes

Why can't sockets be used to identify individuals instead of cookies?

TCP sockets are designed to be stateful so in general they are used to identify sessions. Protocols like SSH and ftp do exactly this. HTTP is designed to be stateless and each connection is only ...
slebetman's user avatar
  • 1,463
8 votes

Why is it a bad design to designate one thread to send data on a socket and the other to receive data?

It isn't necessarily bad design, but in an application with lots of connections it will increase your thread consumption (possibly to the point where you can't create more threads). To support large ...
guest's user avatar
  • 81
5 votes
Accepted

How to efficiently solve "close" players/items in an online game without iterating through all of them?

The standard approach is to divide your world up into large squares/cubes and keep track of which each player is in. You can then iterate over the players in the square the player is in, rather than ...
Ewan's user avatar
  • 77k
5 votes
Accepted

Why does an POST request from HTML/JavaScript generates 401(unauthorized) but it doesn't from a C program?

CORS (Cross-Origin Resource Sharing) Simply allowing javascript to access any network resource is Not a Good Idea TM. Usually javascript is downloaded from a server (not here but out there), but it ...
Kain0_0's user avatar
  • 16.2k
5 votes
Accepted

How do you resolve a byte[] into a class instance in a way that doesn't couple the serialization/deserialization contexts together

The short answer is that you have to provide sufficient metadata to allow the receiver to recognize what to do with the message data.  You want some approach that supports extensibility and loose ...
Erik Eidt's user avatar
  • 34.2k
4 votes

Does a full duplex communication object conflict with single responsibility?

If you would like to split it up into several classes, the Java approach is exactly how you would approach it. class Socket method getInputStream returns InputStream method getOutputStream returns ...
rwong's user avatar
  • 16.9k
4 votes
Accepted

How do network loops actually "catch" connections reliably?

There is a thing called "backlog" which is a queue in which incoming connections temporarily stay until you have had a chance to accept them. It exists precisely so as to allow you to spend some time ...
Mike Nakis's user avatar
  • 32.2k
4 votes

Socket on a webserver

Sockets are file descriptors with special abilities. While every socket somehow uses a port, they are not the same thing. A socket is identified by a local address+port and a remote address+port. ...
amon's user avatar
  • 134k
3 votes

Proper way to send custom data structures by sockets

If you want to send data via sockets, you are best off converting the data first to some textual format (like JSON, or XML). A significant problem with sending binary data over the internet is that ...
Lewis Pringle's user avatar
3 votes
Accepted

Scaling tcp/ip socket server applications

I would recommend looking at distributed pub/sub frameworks. Even if you decide to implement it yourself with TCP/IP instead of using the framework, their architecture should still provide inspiration....
Samuel's user avatar
  • 9,197
3 votes

How do network loops actually "catch" connections reliably?

Listening on a port isn't like running laps around a track and trying to high-five your friend. It's more like running laps around your apartment complex and checking the mailbox every time around. ...
Becuzz's user avatar
  • 4,835
3 votes
Accepted

Does a full duplex communication object conflict with single responsibility?

In addition to the other very good answers here, one way to think about it is that you are not really improving the level of abstraction (in the direction of a full duplex capability) by applying ...
Erik Eidt's user avatar
  • 34.2k
3 votes

UDP order of packets with direct connection

It is possible. I have observed such behaviour on direct connection (no hub or switch) between two machines. In my case it happened only when application sent datagrams one after another without any ...
user305241's user avatar
3 votes

What is the best method for transfer wide range of data into another networked PC?

It sounds like your database comes in too early in the process. I would go with a light queuing solution maybe ZeroMQ? (not sure what you can run on your devices) the key thing I think is for the '...
Ewan's user avatar
  • 77k
3 votes

For interaction by other programs: command line, sockets, or something else?

If you're writing a program to track hours, then don't write it as a standalone command-based utility for a single machine. Just don't. Really. Don't. Instead write a REST server with authentication ...
The Software Barbarian's user avatar
3 votes
Accepted

Where is the difference with client-socket port and server-socket port?

Why we need to open port for server on router, and allow to connect from the outside, but doesn't for client ? If the router performs a network address translation function to translate between the ...
Bart van Ingen Schenau's user avatar
3 votes

How do you resolve a byte[] into a class instance in a way that doesn't couple the serialization/deserialization contexts together

The fundamental basis of communication is that the sender wants the receiver to reach a desirable state (otherwise why would the sender bother?). To achieve this the sender must send a message that ...
Kain0_0's user avatar
  • 16.2k
3 votes

What are the possible *root causes* of a SocketTimeoutException?

To be honest, a socket times out when the server or client fails to respond within the timeout limit. There are many varying causes for this. The only thing you know for certain is that: The server ...
Berin Loritsch's user avatar
2 votes

Does a full duplex communication object conflict with single responsibility?

A full duplex communication line is a single responsibility. Treat it accordingly.
Robert Harvey's user avatar
2 votes

ArrayList Dynamic remove and add for socker client

Use a Map Map<Integer, ClientThread> threads = new HashMap<>(); Add thread to map ClientThread thread = new ClientThread(socket); threads.put(thread.serverUniqueId, thread); Remove a ...
Populus's user avatar
  • 187
2 votes

Socket on a webserver

In a nutshell, when a POSIX-compliant networking stack is in play, each connection to the socket on port 80 will result in its own socket being created when accept() is called. So under the hood ...
RibaldEddie's user avatar
  • 3,283
2 votes

Optimising network data usage in vehicle tracker

Perspective Some back of the envelope calculations to put things into perspective: Let's assume that handling a single such request consumes 2 kB of data. That's 24 kB of data per minute, 1.44 MB ...
jaskij's user avatar
  • 575
2 votes

Do TCP Sockets need validity/security checks?

TCP guarantees that packets will arrive at your application in order - that's one of the main differences between TCP and UDP. If necessary, the TCP stack will buffer up out-of-order packets, and re-...
Simon B's user avatar
  • 9,633
2 votes

Possible microservice based design

I will share a few of my thoughts but please take my word lightly. Microservise's size A microservice can be as big as it needs to be. I remember reading about the pizza rule once, which said that a ...
Cap Barracudas's user avatar
2 votes

Prioritizing messages sent over a socket

There are a lot of details to consider in evaluating the effectiveness of the 5-socket approach and whether a single socket can have equivalent behavior. First, look at the existing system: Is the ...
Hans-Martin Mosner's user avatar
2 votes

Are all sockets implemented as per the Berkeley sockets specification?

No, Berkeley Sockets are not the only networking API. The Wikipedia article you linked to lists a couple of alternatives. The most notable ones are STREAMS, which appeared in Research Unix 8 and are ...
Jörg W Mittag's user avatar
2 votes

Why does an POST request from HTML/JavaScript generates 401(unauthorized) but it doesn't from a C program?

Because that's not allowed in Javascript. Javascript runs in a sandboxed environment; there are a lot of things you are not allowed to do there, such as write to the user's file system. You can ...
Robert Harvey's user avatar

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