Comments (11)
You mentioned at #203 (comment) that his happens at midnight? What happens at midnight on that server and with your application? Aside from that this code looks fine, What is happening at // process data sent from client
?
from socket.
I've found what exactly happen.
I've set IP with port 192.168.0.50:8080 to communicate with the socket server. but when I've checked for the next day the IP is changed to 127.0.0.1:8080.
Below is the solution to communicate with any IP address.
Server.php
$loop = React\EventLoop\Factory::create();
$IP = getHostByName(getHostName()); // this will get current server IP address // 192.168.0.50
$IP = '0.0.0.0'; -> set this to I/O to any IP address
$socket = new React\Socket\Server($IP.':8080', $loop);
$socket->on('connection', function (React\Socket\ConnectionInterface $connection) {
$connection->on('data', function ($data) use ($connection) {
// process data sent from client
});
});
$loop->run();
o sudo lsof -i -P -n | grep LISTEN -> run this cmd to check 8080 port
with updated code, It's showing now *:8080
from socket.
@kailasb10 you mean the IP of the server changes? or is the IP still the same but your socket server isn't listening to the unchanged IP?
from socket.
@kailasb10 you mean the IP of the server changes? or is the IP still the same but your socket server isn't listening to the unchanged IP?
I'm requesting 192.168.0.50:8080 but on the server, it's set to 127.0.0.1:8080 that's why it's not communicating may be getHostByName(getHostName()); this line gives the local IP.
but after restart of supervisor, this line get getHostByName(getHostName()) server IP so it set back to again 192.168.0.50:8080
So I've changed in server.php file to create a connection with 0.0.0.0:8080 it's will start communicating with any IP address.
from socket.
So you say (react)php looses the IP binding at some point in the process?
Switching to the wildcard IP 0.0.0.0 is a workaround but doesn't solve the actual problem.
Just to be on the same page.
- You start your ReactPHP Server
- It binds to
192.168.0.50
in port8080
- it runs several hours without problem and sind bound to
192.168.0.50
- at some point in time it doesn't response anymore
- you check with
lsof -i -P -n | grep LISTEN
ornetstat -lnp
(should be the same result) and see that the PHP process with the same PID runs no on127.0.0.1:8080
- you restart your ReactPHP Server and it works normally again bound to
192.168.0.50
?
from socket.
So you say (react)php looses the IP binding at some point in the process?
Switching to the wildcard IP 0.0.0.0 is a workaround but doesn't solve the actual problem.
Just to be on the same page.
- You start your ReactPHP Server
- It binds to
192.168.0.50
in port8080
- it runs several hours without problem and sind bound to
192.168.0.50
- at some point in time it doesn't response anymore
- you check with
lsof -i -P -n | grep LISTEN
ornetstat -lnp
(should be the same result) and see that the PHP process with the same PID runs no on127.0.0.1:8080
- you restart your ReactPHP Server and it works normally again bound to
192.168.0.50
?
yes
from socket.
AFAIK that's not possible ;-)
Does your server loose the IP or network connect at some point? or maybe use DHCP?
from socket.
Does your server lose the IP or network connection at some point? or maybe use DHCP?
That is a very good point! No clue how the socket server behaves what it expires, that would also depend on the network stack of the OS. But I wouldn't be surprised if it would fall back to the loopback interface and bind on 127.0.0.1
instead, it's unexpected from a consumer's POV. But maybe not so much from a network POV.
Also, if you lose that IP, an active connection might be dropped no matter how long. I kinda assumed you had a very good reason to go for a specific IP, but otherwise use 0.0.0.0
if you don't have a very good reason. Use a firewall to shield it off if you have to. Also look into using an on error
handler on the client's side to reconnect when it disconnects: https://reactphp.org/socket/#connectioninterface
from socket.
Does your server lose the IP or network connection at some point? or maybe use DHCP?
That is a very good point! No clue how the socket server behaves what it expires, that would also depend on the network stack of the OS. But I wouldn't be surprised if it would fall back to the loopback interface and bind on
127.0.0.1
instead, it's unexpected from a consumer's POV. But maybe not so much from a network POV.Also, if you lose that IP, an active connection might be dropped no matter how long. I kinda assumed you had a very good reason to go for a specific IP, but otherwise use
0.0.0.0
if you don't have a very good reason. Use a firewall to shield it off if you have to. Also look into using an onerror
handler on the client's side to reconnect when it disconnects: https://reactphp.org/socket/#connectioninterface
I've observed that this will happen when the server restart.
I've checked in VM it creates an issue when the next day I've started & the same will happen when I've restarted my AWS server.
I think when the server started the supervisor is also restarted that time somehow it didn't get the server IP then it points to the local IP
I think when we get NULL IP address then it points to local IP (127.0.0.1) address
from socket.
Thanks for you answer. It looks like that's a completely different scenario compared to my understanding of you description.
In this case I would expect ReactPHP (actually the underlying layers down to the kernel) behaves correctly. At point in time when your application starts you get the IP that exists in the system which is at least localhost. That means you application starts too early.
I don't know which supervisor you use, I can only suggest to change the start dependencies the way your application is started after the network stack is ready.
The good thing is that is not a ReactPHP issue 😅
from socket.
Thanks for you answer. It looks like that's a completely different scenario compared to my understanding of you description.
In this case I would expect ReactPHP (actually the underlying layers down to the kernel) behaves correctly. At point in time when your application starts you get the IP that exists in the system which is at least localhost. That means you application starts too early.
I don't know which supervisor you use, I can only suggest to change the start dependencies the way your application is started after the network stack is ready.
The good thing is that is not a ReactPHP issue 😅
yes. It's not ReactPHP issue :)
from socket.
Related Issues (20)
- Keep tcp connection alive HOT 2
- Certificates using mkcet fail handshake HOT 4
- Additional suggestion HOT 2
- Get write response HOT 2
- Problem with DNS request in socket connector HOT 3
- verify_peer should default to false for React\Socket\Server using TLS context HOT 1
- TcpConnector - are writes buffered or sent immediately? HOT 10
- Listening multiple socket chanels on the same server HOT 2
- Write never send data HOT 2
- Failed tests with OpenSSL 3 HOT 5
- EventBase::loop(): kevent: Bad file descriptor HOT 6
- [Security] Response size limitation HOT 2
- [v1.11.0] Accessing array offset on null value - Failed TCP connection without ext-sockets HOT 2
- How to handle socket connection on Server HOT 4
- Interactive client example? HOT 2
- How to deploy the server? HOT 1
- New to reactphp : I think my problem is easy for you HOT 3
- Memory leak in TcpServer due to PHP stream_context_create memory leak HOT 5
- Roadmap to reactphp/socket v3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from socket.