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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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. ...
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 ...
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....
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 ...
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. ...
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 ...
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 '...
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 ...
3
votes
Keeping deploys in Sync
This depends on your architecture. When you deploy a web client and a web server, you cannot guarantee matching versions even if you deploy both at the same instant. Even if there is no caching at ...
3
votes
Accepted
Receiving errors without engaging in excessive communication when using sockets
There are four ways to approach client-server communications:
Synchronous: every request receives a response of some form.
In this approach, the client will wait for a response after every request, ...
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 ...
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 ...
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 ...
2
votes
Accepted
SDL_net how to get the UDP remote address?
Your TCP connection "doesn't know" anything about any UDP connections. If you established TCP connection and want to send additional UDP packets, you will have to determine the the correct port ...
2
votes
Does a full duplex communication object conflict with single responsibility?
A full duplex communication line is a single responsibility. Treat it accordingly.
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 ...
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 ...
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 ...
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-...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
sockets × 135networking × 26
java × 20
tcp × 17
c++ × 15
c × 12
c# × 11
multithreading × 10
websockets × 10
python × 9
server × 9
client-server × 8
networks × 8
design × 7
node.js × 7
http × 6
android × 5
linux × 5
protocol × 5
design-patterns × 4
architecture × 4
.net × 4
javascript × 3
php × 3
database × 3