There is an application on the server, listening to port 7777 and waiting for a ws: // connection

Briefly about how it should work: Browser -> Nginx (HTTPS) -> WS Server (here we want not to use the certificate, which is why such problems)

The problem is that for some reason, when sending data to the server, only part of the messages from JS arrive:

Sending data in chrome What we get on the server

Always comes 1 letter from the message, which is very strange. I tried to run all the same on the local Windows machine, everything works as it should.

Launched on c # using websocket-sharp

WebSocketServer srv = new WebSocketServer(7777); srv.AddWebSocketService<MyClient>("/ws");//сюда Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΏΠ΅Ρ€Π΅Π½Π°ΠΏΡ€Π°Π²Π»ΡΡ‚ΡŒ proxy_pass srv.Start(); Console.WriteLine("Server is listening......"); //простой listener с Π²Ρ‹Π²ΠΎΠ΄ΠΎΠΌ Π΄Π°Π½Π½Ρ‹Ρ… class MyClient : WebSocketBehavior { protected override void OnOpen() { Write("Client Connected!", ConsoleColor.Green); } protected override void OnClose(CloseEventArgs e) { Write("Close connection: "+ e.Reason, ConsoleColor.Red); } protected override void OnError(ErrorEventArgs e) { Write("Error: "+e.Message, ConsoleColor.DarkRed, ConsoleColor.Gray); } protected override void OnMessage(MessageEventArgs e) { Write(e.Data); } } 

Simple JS client:

 var socket = new WebSocket("wss://ΠΌΠΎΠΉ-сайт/Game"); socket.onopen = function() { console.log("Π‘ΠΎΠ΅Π΄ΠΈΠ½Π΅Π½ΠΈΠ΅ установлСно."); activeBtns(false); }; socket.onclose = function(event) { if (event.wasClean) { console.log('Π‘ΠΎΠ΅Π΄ΠΈΠ½Π΅Π½ΠΈΠ΅ Π·Π°ΠΊΡ€Ρ‹Ρ‚ΠΎ чисто'); } else { console.log('ΠžΠ±Ρ€Ρ‹Π² соСдинСния'); // Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, "ΡƒΠ±ΠΈΡ‚" процСсс сСрвСра } console.log('Код: ' + event.code + ' ΠΏΡ€ΠΈΡ‡ΠΈΠ½Π°: ' + event.reason); activeBtns(true); }; socket.onmessage = function(event) { console.log("ΠŸΠΎΠ»ΡƒΡ‡Π΅Π½Ρ‹ Π΄Π°Π½Π½Ρ‹Π΅ "); console.log(event.data); }; socket.onerror = function(error) { console.log("Ошибка " + error.message); activeBtns(true); }; activeBtns(); sendData = function(){ socket.send("test message"); }; 

On the server (OS: Ubuntu) there is Nginx with settings (installed clean v1.14.1):

 user www-data; worker_processes auto; pid /run/nginx.pid; include /etc/nginx/modules-enabled/*.conf; events { worker_connections 768; # multi_accept on; } http { sendfile on; keepalive_timeout 604800; proxy_connect_timeout 604800; proxy_send_timeout 604800; proxy_read_timeout 604800; include /etc/nginx/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } #ΠΊΠΎΠ½Ρ„ΠΈΠ³ ΠΌΠΎΠ΅Π³ΠΎ Π΄ΠΎΠΌΠ΅Π½Π°: server { listen 443 ssl; server_name ΠΌΠΎΠΉ-сайт; #Ρ‚ΡƒΡ‚ ΠΌΠΎΠΉ Π΄ΠΎΠΌΠ΅Π½ access_log /etc/nginx/logs/log.access; error_log /etc/nginx/logs/log.error error; ssl on; ssl_certificate /etc/ssl/certs/cert.pem; ssl_certificate_key /etc/ssl/private/cert.key; client_max_body_size 1M; client_body_buffer_size 1M; location / { root /var/www/ΠΌΠΎΠΉ-сайт/html; index index.html index.htm; } location /Game { proxy_pass http://ΠΌΠΎΠΉ-сайт:7777/ws; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } } 

Perhaps there are some other settings that can be changed?

    1 answer 1

    The problem is in the server. Put the server node.js and it all worked