R
R
romanoza2011-01-31 13:18:38
PHP
romanoza, 2011-01-31 13:18:38

Multithreading, sockets, php?

Kind.

There is a socket server in php, several clients connect to it, the order of communication is as follows:

клиент шлет серверу свой id<br/>
сервер отвечает, что id принят<br/>
клиент шлет серверу инфу<br/>
сервер отвечает, что инфа принята


I can’t understand how, in the case of a connection by several clients, to distinguish one from the other while saving data, because it can turn out like this:

cliend1id<br/>
client2id<br/>
client1data<br/>
client2data<br/>

accordingly, instead of the data of client 2, I will receive the data of client 1

Answer the question

In order to leave comments, you need to log in

4 answer(s)
J
Jazzist, 2011-01-31
@Jazzist

Pay attention to the so-called "session mechanism", or at least "identifiers". Google, and even Wikipedia - both concepts.

R
romanoza, 2011-01-31
@romanoza

thanks, the problem is that I didn’t find exactly the way to get the session ID
, only creating an array clientId=>socket connection resource comes to mind

A
Alexey Ashurok, 2011-01-31
@AotD

For a socket server in php, you can take a specialized solution phpDaemon or nanoserv.
The last user used it himself, all users are separated by sockets and nothing gets mixed up anywhere)

A
Anatoly, 2011-02-01
@taliban

Why don't you send the ID along with the data? Browsers do just that, oddly enough.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question