1

How do I send a message from a PHP-client to a C-server using a socket. I need simple code, one TCP-connection.

The client is written in PHP and the server in C on Windows.

default
  • 11,485
  • 9
  • 66
  • 102
gilit
  • 39
  • 1
  • 2
  • 1
    What have you done so far? There are many many C socket tutorials on the internet – mathematician1975 Sep 05 '12 at 15:16
  • 1
    C or C++? It's OK to have vague questions, but you should put enough effort into thinking about your problem to agree on the *language* you want to use. – Kerrek SB Sep 05 '12 at 15:18
  • possible duplicate of [PHP Communication with C++ Application](http://stackoverflow.com/questions/4021029/php-communication-with-c-application) – Ja͢ck Sep 05 '12 at 15:22
  • It is C++ . I saw some example in C. I saw some examples in php. I dont know to connect them – gilit Sep 05 '12 at 17:46
  • is it C or C++ or any of them? can you edit your question/title to avoid confusion? – bubakazouba Dec 29 '15 at 01:30
  • http://stackoverflow.com/questions/4789720/communicate-c-program-and-php/ http://stackoverflow.com/questions/28261364/what-is-a-good-inter-process-communication-method-between-c-and-php-in-linux – Bernardo Ramos Apr 15 '17 at 03:06
  • http://stackoverflow.com/questions/1746207/how-to-ipc-between-php-clients-and-a-c-daemon-server – Bernardo Ramos Apr 15 '17 at 03:22

1 Answers1

0

See at first example here.

$socket = socket_create(AF_UNIX, SOCK_DGRAM, 0);  //AF_UNIX - it's important!
$socket_file = dirname(__FILE__) . '/socket_file.sock';
socket_bind($socket, $socket_file);
socket_recvfrom($socket, $some_buf, $input_buf_size, 0, $from);
socket_sendto($socket, $some_buf, $some_buf_len, 0, $from);

More info.

Ivan Velichko
  • 6,348
  • 6
  • 44
  • 90