Re: Help getting a socket to work?
From: Pjotr Wedersteers (x33159_at_westerterp.com)
Date: 09/03/04
- Next message: Tim Tyler: "Re: PHP global namespace clogged up"
- Previous message: Pjotr Wedersteers: "Re: Need links/docs showing approved usage of PHP in DoD/Govt."
- In reply to: Martin: "Help getting a socket to work?"
- Next in thread: Daniel Tryba: "Re: Help getting a socket to work?"
- Reply: Daniel Tryba: "Re: Help getting a socket to work?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 3 Sep 2004 08:28:28 +0200
Martin wrote:
> I am a PHP newbie (just got my "Hello World" page working this
> morning). I'm doing some R&D work to see if PHP is viable for a
> situation I have. To accomplish what I want to do, I have to have the
> PHP page communicate directly with another process.
>
> I want the PHP script to establish a socket connection to the other
> process, send a message and receive some data back which would then
> used for calculations and/or display on the resulting page. The PHP
> page will be the client - the other process will be the server. The
> server process is a program that I've written using Visual Basic 6 and
> the socket there is the standard Winsock that's part of VB.
>
> Shown below is the entire page that I'm using to test this concept;
> I've adapted it from an example provided in the "Socket Functions"
> section of the manual on the PHP.net website. Amazingly enough, this
> actually works - up to a point. I'm hoping someone here can help get
> it working all the way through.
>
> This script works up to the point of reading the response. It creates
> the connection (my server process accepts the connection and receives
> the "Hello world" message). The server sends its message. But then the
> script seems to just sit there - it doesn't complete - it doesn't
> generate any output.
>
> Can anyone suggest what I might need to do to get this to work?
>
> If it matters, I'm using PHP 5.0.1, IIS 5.1 running on Windows XP with
> service pack 2.
>
> Thanks
>
>
> --------------------------------------------------------------------------
---------
> <HTML>
> <BODY>
>
> <?php
> echo "<h2>TCP/IP Connection</h2>\n";
>
> $service_port = 1001;
> $address = "192.168.200.19";
>
> $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
> if ($socket < 0) {
> echo "socket_create() failed: reason: " . socket_strerror($socket)
> . "<br>";
> } else {
> echo "OK.<br>";
> }
>
By the way, you can use this construction as well for testing and stuff, as
many of the PHP functions return FALSE when failed.
Very common, easier to maintain too.
$socket = socket_create (AF_INET, SOCK_STREAM, SOL_TCP) or die
socket_strerror($socket);
echo "OK <br>";
- Next message: Tim Tyler: "Re: PHP global namespace clogged up"
- Previous message: Pjotr Wedersteers: "Re: Need links/docs showing approved usage of PHP in DoD/Govt."
- In reply to: Martin: "Help getting a socket to work?"
- Next in thread: Daniel Tryba: "Re: Help getting a socket to work?"
- Reply: Daniel Tryba: "Re: Help getting a socket to work?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|