Hello, i try to connect to a server(writen in c) that i am running locally in my pc but after
connecting, writing some data and getting a reply the connection closes. The server doesn't
have a problem as in telnet there is no problem.
Socket problems
Moderator: General Moderators
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Socket problems
PHP is NOT typically run in a tsr mode...so thats likely where your problems are coming in...vasilanthropos wrote:Hello, i try to connect to a server(writen in c) that i am running locally in my pc but after
connecting, writing some data and getting a reply the connection closes. The server doesn't
have a problem as in telnet there is no problem.
PHP executes...opens connections...does it's business and regardless of whether you explicitly close a socket connection or any resource connection...that connection is closed and cleaned up by garbage collection facilities...
Some connections can be made persistent, like mysql_pconnect() for instance...but I'm not so sure how that works in PHP as PHP applications don't have an message pump or any way of interacting/manipulating the direction of code execution...except through GET/POST/ENVARS/etc...sooo...unless that connection is somehow persisted through requests (sessions don't allow resources to be persisted) I'm not sure what you can do about it...
After re-reading your message I'm not sure I understand what your asking...
Why don't you just close the connection directly in PHP??? Before script termination?
You'll likely want to have your own script dedicated to listening to the connection. An infinite loop is a possibility...
Obviously if the server crashes for some reason, this loop won't work. So perhaps a cronjob to check the connection as well wouldn't be a bad idea.
Code: Select all
while(TRUE){
//listen for data, slice it, dice it, serve it somewhere
}Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
-
vasilanthropos
- Forum Newbie
- Posts: 3
- Joined: Thu May 18, 2006 6:23 pm
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
-
vasilanthropos
- Forum Newbie
- Posts: 3
- Joined: Thu May 18, 2006 6:23 pm
If you're running this through a script, your connection to the socket will terminate at the end of the script.
You should put it inside of a loop to keep the connection open.
You should put it inside of a loop to keep the connection open.
Code: Select all
while($display=socket_read.....){
//
}
//or
while(TRUE){
if($display=socket_read()){
echo $display;
}
}Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.