473,566 Members | 2,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UNIX Socket does not send data until closed

Hi,

I am using PHP persistent sockets and have a problem with them. The
problem is that PHP only sends the data when the socket is closed. In
the code example below the counterparty process (peer) received the
connect request from PHP, but then never receives the message sent in
the "fwrite" command below - and consequently never generates the
reply which should be read by the fgets command.

Flushing the socketFP does not make any difference - the only thing
that causes the data to be sent is to fclose it (which defeats the
purpose of having persistent sockets, which I definitely need).

Any help much appreciated.

System:
PHP version 5.2.0-8+etch7, Debian Linux 2.6.18-4-486

Best regards

------------------ Code Sample -----------------------------------
$SocketFP = pfsockopen("uni x:///tmp/hs.socket",0,$e rrno,$errstr);
if ($SocketFP == FALSE) {
... error handling
}

stream_set_time out($SocketFP,2 );
stream_set_bloc king($SocketFP, 1);
$Msg = sprintf("Connec tId %d\n\r",$OurId) ;
$i =fwrite($Socket FP,$Msg);
fflush($SocketF P);

if ($i==FALSE) {
... error handling
}

$message = fgets($SocketFP );

Jul 24 '07 #1
1 2960
C.
On 24 Jul, 17:35, Chris <dr_christopher _hega...@hotmai l.comwrote:
Hi,

I am using PHP persistent sockets and have a problem with them. The
problem is that PHP only sends the data when the socket is closed. In
the code example below the counterparty process (peer) received the
connect request from PHP, but then never receives the message sent in
the "fwrite" command below - and consequently never generates the
reply which should be read by the fgets command.

Flushing the socketFP does not make any difference - the only thing
that causes the data to be sent is to fclose it (which defeats the
purpose of having persistent sockets, which I definitely need).
------------------ Code Sample -----------------------------------
$SocketFP = pfsockopen("uni x:///tmp/hs.socket",0,$e rrno,$errstr);
if ($SocketFP == FALSE) {
... error handling
}

stream_set_time out($SocketFP,2 );
stream_set_bloc king($SocketFP, 1);
$Msg = sprintf("Connec tId %d\n\r",$OurId) ;
$i =fwrite($Socket FP,$Msg);
fflush($SocketF P);

if ($i==FALSE) {
... error handling
}

$message = fgets($SocketFP );
stream_set_bloc king($SocketFP, 1);
- doesn't it open the socket in blocking mode anyway? (not sure how
much sense fflush() would make if it were non-blocking).

I suspect its not relevant, though ISR something about newlines and
flushes on streams - but your script above does have a newline char -
but normally where a line is terminated by a CR and LF, the CR comes
first. This may be a problem - I'd try with a different client but
don't know of a generic tool for Unix domain sockets - nc will work
for a TCP socket though.

I'd also suggest checking the value of $i and what fflush() returned.

HTH

C.

Jul 25 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
11665
by: Terry | last post by:
It's my understanding of UDP sockets that if there is a thread blocked on a "recvFrom()" call and other thread sends a UDP packet to some address, that if the machine on the other end isn't up, that the "recvFrom()" call should just continue blocking. Right? What I'm seeing is that when I send a packet to a particular address that is not...
4
18097
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed as I find appropriate. I am using the socket asynchronously by calling the BeingSend and BeginReceive calls. I would like to be able to call...
13
2635
by: coloradowebdev | last post by:
i am working on basically a proxy server that handles requests via remoting from clients and executes transactions against a third-party server via TCP. the remoting site works like a champ. my problem is executing the transactions against the remote server and returning the response to the remoting client. i can open the socket fine and,...
9
8309
by: craig.overton | last post by:
All, I am currently developing an FTP class in VB.NET. It's kid tested, mother approved when trying to access an FTP Server on a Windows box meaning I can connect, run commands, upload and download a file no problem. My issues come when I try to use the same class with the same commands to access an FTP server on a UNIX box. I can connect...
2
13142
by: yvan | last post by:
Hi, Here is my client/server scenario: Step1: Client connects to server and sends data sucessfully (using Socket.Send()). Step2: Server gracefully exists (calls Socket.Shutdown() and Socket.Close()). I see the server connection status go from ESTABLISHED to FIN_WAIT2, the client connection go from ESTABLISHED to WAIT_CLOSE. Step3:...
5
3088
by: Kurt | last post by:
I have a client & server app which communicates using the socket class. If I shutdown the server closing the socket the client still thinks the socket is open. Even calling send does not throw an exception. Thanks Kurt
0
1473
by: Holly | last post by:
I copied this code that works to connect into Unix. I am looking for a way to get it to work with a secure Unix box. Anyone have any insights on how to do this? I am trying to build an sftp service. Thanks Holly Imports System Imports System.Net Imports System.IO
4
4303
by: Adam Clauss | last post by:
A while back I posted regarding a problem we were having with one of our applications which was randomly crashing. Monitoring memory usage revealed a spike in nonpaged pool memory just prior to the crash each time. We finally think we have narrowed down the cause of this to a user (located semi-remotely) who would connect into our system...
0
7673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8109
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6263
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.