I want to make a chat to my site for example. And the server I want to write on with #. Is it possible to do that? For example, here’s what I’m saying on the server:

const int port = 8888; // ΠΏΠΎΡ€Ρ‚ для ΠΏΡ€ΠΎΡΠ»ΡƒΡˆΠΈΠ²Π°Π½ΠΈΡ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠΉ static void Main(string[] args) { TcpListener server = null; try { IPAddress localAddr = IPAddress.Parse("127.0.0.1"); server = new TcpListener(localAddr, port); // запуск ΡΠ»ΡƒΡˆΠ°Ρ‚Π΅Π»Ρ server.Start(); while (true) { Console.WriteLine("ОТиданиС ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠΉ... "); // ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ входящСС ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ TcpClient client = server.AcceptTcpClient(); Console.WriteLine("ΠŸΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ ΠΊΠ»ΠΈΠ΅Π½Ρ‚. Π’Ρ‹ΠΏΠΎΠ»Π½Π΅Π½ΠΈΠ΅ запроса..."); // ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ сСтСвой ΠΏΠΎΡ‚ΠΎΠΊ для чтСния ΠΈ записи NetworkStream stream = client.GetStream(); // сообщСниС для ΠΎΡ‚ΠΏΡ€Π°Π²ΠΊΠΈ ΠΊΠ»ΠΈΠ΅Π½Ρ‚Ρƒ string response = "ΠŸΡ€ΠΈΠ²Π΅Ρ‚ ΠΌΠΈΡ€"; // ΠΏΡ€Π΅ΠΎΠ±Ρ€Π°Π·ΡƒΠ΅ΠΌ сообщСниС Π² массив Π±Π°ΠΉΡ‚ΠΎΠ² byte[] data = Encoding.UTF8.GetBytes(response); // ΠΎΡ‚ΠΏΡ€Π°Π²ΠΊΠ° сообщСния stream.Write(data, 0, data.Length); Console.WriteLine("ΠžΡ‚ΠΏΡ€Π°Π²Π»Π΅Π½ΠΎ сообщСниС: {0}", response); // Π·Π°ΠΊΡ€Ρ‹Π²Π°Π΅ΠΌ ΠΏΠΎΡ‚ΠΎΠΊ stream.Close(); // Π·Π°ΠΊΡ€Ρ‹Π²Π°Π΅ΠΌ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ client.Close(); } } catch (Exception e) { Console.WriteLine(e.Message); } finally { if (server != null) server.Stop(); } } 

How can I make a simple client for this server?

 const io = require("socket.io-client"), ioClient = io.connect("http://localhost:8888"); ioClient.on("seq-num", (msg) => console.info(msg)); 

Connected, but messages do not come. I do not delve into this node. I did not find an example of this type on the Internet. How to dig, where to dig, what to read to understand?

    1 answer 1

    Yes. You can use any C # libu that can work with websockets. However, as I recall, socket.io can work with regular ajax. In this case, you can try to raise the usual http server.

    And of course, working with JSON is necessary in both cases. The easiest way to search for the protocol is to open the source code for socket.io .