P
P
pentagon97142016-07-31 06:57:15
PHP
pentagon9714, 2016-07-31 06:57:15

How to implement a chat (or almost a chat) in SI + php?

A complete noob in programming client-server applications and sockets in particular, but I have experience with C and PHP. I want to implement a text messaging system between remote machines by writing a console application in C and some server part in PHP. The server part is supposed to be hosted on a free hosting.

At the moment, all that has been done is to implement sockets on the local machine.

The questions are as follows:
1. Is it even possible to implement something like this using only C and PHP? If not, what should be used and what sources should be studied?
2. What are the ways to send data from the server to the client?
3. What is the best way to send data from the client to the server?

I would be grateful if you give examples of the implementation of something similar.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Koryukov, 2016-07-31
@pentagon9714

It can be implemented, but PHP is not very suitable for organizing chats and similar things, where the server must keep a connection with many clients and initiate the sending of data.
It is better to look in the direction of NodeJS, go, Java, Python...
All high-level protocols for the interaction of computers over a network are based on a socket connection. When you work in a browser, you can't use it, you only have http (ajax is also http), dirty hacks like long polling, and the now fashionable WebSocket.
If the client is written in C, and indeed on anything that supports sockets, then there’s nothing to even guess. PHP has an extension for working with sockets. Previously, it seemed that it was not very good, and only perverts work with it. It and is clear - PHP is ground under http.
In fact, it is necessary to come up with or implement an already known one, or even take a library in which the communication protocol between the client and the server is already programmed.
In fact, just as http with its headers and request body is a protocol over TCP, then you also need to come up with / take a ready-made protocol of the same level - over TCP.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question