Socket issue

Solved
amidepittour Posted messages 7 Status Membre -  
 Gremy -
Configuration: Windows Vista / Firefox 3.6.3

Hello, here is my problem.
I am working on sockets and here is the message:
socket_connect() [function.socket-connect]: unable to connect [0]: No connection could be made because the target computer actively refused it.

Here is the code:
<?php //Server details $port = 24243; $address = "127.0.0.1"; /* Create a TCP/IP socket. */ $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 />"; echo "Trying to connect to $address on port '$port'..."; $result = socket_connect($socket, $address, $port); if ($result < 0) echo "socket_connect() failed: reason: ($result) " . socket_strerror($result) . "<br />"; else echo "OK.<br />"; $send = 'plap'; echo "Sending request $send ..."; socket_write($socket, $send, strlen($send)); echo "OK.<br />"; echo "Reading response: <br /><br />"; while ($response = socket_read($socket, 2048)) echo $response; echo "<br />Closing the socket..."; socket_close($socket); echo "OK.<br /><br />"; ?> 


Thank you

3 réponses

Gremy
 
```html "echo "Trying to connect to $adress on port '$port'...";"

$address with an "e"

do you have an active socket, started as a server, let me explain.

your socket_connect() is used to connect 2 sockets (a client to a server) if you don't have a server to connect to, the socket connect will not work.

to create a server to connect to:

socket_create
socket_bind
socket_listen
...

hoping to help you ```
3