开发者

PHP client communicate with C++ Server over TCP

Im trying to get a Php page to be able to communicate with a C++ server. It must be able to reciv开发者_JAVA百科e and send at all time (and the same time). When the php page recives a string it shall make some changes in Mysql db but at the same time send other strings to the server.

You can think of it as a chat, but then the php recive a string it shall be formated.

The C++ server is up and running only the php client side is a mystery for me.

Is there any example code that anyone can help me with?

Thx!


Well first of all you need to understand and remember that PHP in itself is stateless. You can have PHP receive a request and parse it and do something with the gained information, but after that the request closes.

One solution you could try is having your C++ app HTTP POST to a PHP script. This script can parse and analyze the request and take action upon it.

  1. Store something in the database
  2. Create a response
  3. Output the response

The C++ app can then do something with the response.

This will work but if your actual use case is a chatroom or something of the likes there are better solutions than using PHP.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜