Linqan
Linqan

Reputation: 355

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 recive 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!

Upvotes: 1

Views: 591

Answers (1)

hoppa
hoppa

Reputation: 3041

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.

Upvotes: 1

Related Questions