No, your problem is most likely that you didn't do anything with the telnet
negotiation phase.

Read the RFC on telnet, and you will find that there is a whole
client-server negotiation phase going on. Kinda like a modem handshake.
It is really quite difficult, and no one has ported a Telnet class to PHP
yet. (big big task)

There is a Net::Telnet class in perl that I ended up using to write a script
to do something similar, and pass results back to the php script that called
it.

Telnet is simply not as easy as opening a socket. If you don't send the
right set of characters as the first block, it won't work.


On 4/9/01 10:16 AM, "Matthias Winkelmann" <[EMAIL PROTECTED]> wrote:

> Hi!
> 
> I'm trying to speed up a big application by splitting it into a codebase
> acting as a server and the actual scripts communicating with the server
> using sockets.
> 
> I got the server working, at least it works when I send a request via
> telnet. When I try to let a script act as the client I get no response. I
> think the problem is the length parameter in the read()-function.
> Not all requests and results are 2048 bytes, but I have no idea what to use
> as a delimiter instead.
> Here are the scripts so far:
> 
> Server:
> 
> // Socket was created, bind & listen executed
> do {
>   if (($msgsock = accept_connect($sock)) < 0) { // wait for request
>       echo "accept_connect() failed: reason: " . strerror ($msgsock) .
> "\n";
>       break;
>   }
>   do {
>       $buf = '';
>       $ret = read ($msgsock, $buf, 2048);         // read request
>       echo "request: $ret <br>";
>       if ($ret < 0) {
>           echo "read() failed: reason: " . strerror ($ret) . "\n";
>           break 2;
>       }
>       if ($ret == 0) {
>           break 2;
>       }
>       $buf = trim ($buf);
> 
>       $talkback = eval($buf);                                    //
> request verabeiten
>       write ($msgsock, $talkback, strlen ($talkback)); // write result to
> socket
>       echo "$buf\n";
>   } while (true);
>   close ($msgsock);
> } while (true);
> 
> 
> 
> Client:
> 
> 
> // Socket was created; submitting request
> 
> write ($socket, $in, strlen ($in));
>        while (read ($socket, $out, 2048))  // reading response. what if
> the response is < 2048 bytes?
>              {
>              echo $out;
>              }
> 
> 
> As I said: The server works perfectly using telnet, but the script-client
> does not give any output, allthough the connection was created successfully.
> 
> Thanks in advance for any answers. I hope I was able to describe the problem
> well enough.
> 
> Matt
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to