Richard Luckhurst wrote: > Hi List > > I am working with an application that has to run as a socket listener. It > receives a string from another application on a certain socket and then does > some processing and then passes the result back to the client application via > the socket. Here is the listener code I am using > > while(true) > { > $client = socket_accept($socket); > > $arev_data = socket_read($client, 1024); > > $yresponse = build_XML_request($arev_data); > > socket_write($client, $yresponse); > > socket_close($client); > > } > socket_close($socket); > > The application is working fine but I have just noticed that when the $yresponse > variable is larger than 1024 bytes the string returned to the client is > truncated. I just had a look at the php manual for socket_write and it > mentions that truncating the data at the buffer size can be a problem. The > manual does not offer any possible solutions though. I am stumped here as the > value for $yresponse will often be larger than 1024 bytes and its length is > quite variable. > > Does anyone have any suggestions on how I can make sure the entire contents of > $yresponse are passed back to the client? I would start by reading the relevant page: http://php.net/socket_write after reading that your first attempt will probably be this (you may have complication is your using a multibyte charset): socket_write($client, $yresponse, strlen($yresponse)); if that doesn't work, you will be looking at capturing the return value of socket_write() in order to determine how many bytes were sent ... this information will allow to to use a loop to call socket_write as many times as is required to send all the data. hope that makes sense to you. > > > > > Regards, > Richard Luckhurst > Product Development > Exodus Systems - Sydney, Australia. > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php