如何通过套接字在PHP和c++应用程序之间进行通信?

时间:2021-10-27 22:24:45

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

如何使用套接字将消息从php客户机发送到c服务器。我需要简单的代码,一个tcp连接。

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

客户机是用PHP编写的,服务器是在Windows上用C编写的。

3 个解决方案

#1


0  

There is some information using the google keywords: PHP C++ Communication.

有一些信息使用谷歌关键字:PHP c++通信。

And specifically at the similar(identical) qusetion here: PHP Communication with C++ Application

特别是类似的(相同的)问题:与c++应用程序的PHP通信

#2


0  

Maybe this can help you in some way? http://git.jelmerdroge.nl/socket-segedp/src

也许这能在某种程度上帮助你?http://git.jelmerdroge.nl/socket-segedp/src

It's not a true connection between C and PHP, but it illustrates the work of Sockets and maybe you can use this in some way or get ideas on how to solve you problems you might run in to.

它不是C和PHP之间的真正连接,但是它说明了socket的工作,也许您可以用某种方式使用它,或者了解如何解决您可能遇到的问题。

--

- - -

This is just a project I made for school once, we had to create a socket based application. So I decided to build something like a Command prompt where you can do stuff with. You can access it through Putty, so it should be possible with purely C as well.

这只是我为学校做的一个项目,我们必须创建一个基于套接字的应用程序。所以我决定构建一个命令提示符之类的东西,你可以用它来做一些事情。您可以通过Putty访问它,因此也可以使用纯C。

#3


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.

更多信息。

#1


0  

There is some information using the google keywords: PHP C++ Communication.

有一些信息使用谷歌关键字:PHP c++通信。

And specifically at the similar(identical) qusetion here: PHP Communication with C++ Application

特别是类似的(相同的)问题:与c++应用程序的PHP通信

#2


0  

Maybe this can help you in some way? http://git.jelmerdroge.nl/socket-segedp/src

也许这能在某种程度上帮助你?http://git.jelmerdroge.nl/socket-segedp/src

It's not a true connection between C and PHP, but it illustrates the work of Sockets and maybe you can use this in some way or get ideas on how to solve you problems you might run in to.

它不是C和PHP之间的真正连接,但是它说明了socket的工作,也许您可以用某种方式使用它,或者了解如何解决您可能遇到的问题。

--

- - -

This is just a project I made for school once, we had to create a socket based application. So I decided to build something like a Command prompt where you can do stuff with. You can access it through Putty, so it should be possible with purely C as well.

这只是我为学校做的一个项目,我们必须创建一个基于套接字的应用程序。所以我决定构建一个命令提示符之类的东西,你可以用它来做一些事情。您可以通过Putty访问它,因此也可以使用纯C。

#3


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.

更多信息。