has any one come across a problem when reading from a socket that sockets information are interchanged. I have a web server and using sockets i get information from another server but it so happened that two users logged in at the same time and their information was interchanged; meaning user1 got some of user2 info and user2 got some of user1 info.

please anyone give me a hint on where to begin troubleshooting this scenario.

Once I had a problem similar to this but it was the sessionid that was generated as the same for both users and i fixed it by adding the user name to the sessionid.


Abraham Obando

peculiar... is there some code you could post?
Are you using persistent sockets?
Whats the protocol used to talk to the remote server?
could also be an issue was with the remote server.

here is the function i use to send and recieve a message to the other server using xml.

function SendMessage($IsXMLalready=false)
       {                                
                global $Redirect;
                $Authorized = true;
                $this->process_return = true;    
    
          //Init other parameters
          $this->TMS = Date("YmdHis") + rand(1,1000);
          $this->LOG = Date("YmdHis")+  rand(1,1000);
          $this->XML->HDR->TMS  = $this->TMS;
          $this->XML->HDR->LOG  = $this->LOG;

         
          $this->Message = SolveReturnXML($this->Message);
          $this->LOGSentMessage = $this->Message;    
         
           $sizeofit = pack("n*",strlen($this->Message)); //header with the ize information
                $this->Message = $sizeofit.$this->Message; //Concatenate header + message
              $MySocket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

            if (!$MySocket)
            {
                        AddCustomMessage("LOG","ERR","System is down.");
                    header("Location: SystemDown.php");
                        $this->process_return = false;
                }
                else
                  {
                      //Connect to Socket
                   if (!socket_connect($MySocket, (string)$this->IBMIp , (integer)$this->IBMPort))
                    {
                                 AddCustomMessage("LOG","ERR","System is down.");
                                 header("Location: SystemDown.php");
                                 $this->process_return = false;
                          }
                  else
                     {
                                //$this->WriteWEBLOGMessage(">>>Writing to Socket Message Size ".strlen((string)$this->Message));
                         $numbytes = socket_write($MySocket,(string)$this->Message,strlen((string)$this->Message));
                                //Write Log Sent
                                $this->WriteLogSent();                        
                      //read the two bytes from header

                if ($this->WaitResponse)
                                     {
                          $result = socket_read($MySocket,2,PHP_BINARY_READ);
                        $x = unpack("n*",$result);
                            $sizereceived   = (integer)$x[1];
                                        $pendingbytes   = $sizereceived;
                                        $internalbuffer = "";
                                        $this->RETMessage = "";
                                        
                                        while ($pendingbytes > 0)
                                          {
                                            $internalbuffer = socket_read($MySocket,$pendingbytes ,PHP_BINARY_READ);
                                                $this->RETMessage .= $internalbuffer;
                                                $pendingbytes = $pendingbytes - strlen($internalbuffer);
                                          }

                               } //end if ($this->WaitResponse)

                           socket_close($MySocket);
                           unset($MySocket);
                                                  
                         }  // end if connect to socket

                    } // end if create a socket
          
                 
    } //End Function Send Message
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.