php-socket

Sending sockets data with a leading length value

倾然丶 夕夏残阳落幕 提交于 2019-12-05 13:13:05
I want to send JSON messages from a PHP script to a C# app over a network connection using PHP Sockets . Usually, for binary protocols, the first 4 bytes of every message must be an integer which represents the length (how many bytes) of the message. In C# I prefix every message with an integer that tells the length of the message as follow: byte[] msgBytes = UTF8Encoding.UTF8.GetBytes("A JSON msg"); byte[] prefixBytes = BitConverter.GetBytes(msgBytes.Length); byte[] msgToSend = new byte[prefixBytes.Length + msgBytes.Length]; Buffer.BlockCopy(prefixBytes, 0, msgToSend, 0, prefixBytes.Length);

Web socket not working in Firefox 12

大兔子大兔子 提交于 2019-12-01 07:09:36
问题 Firefox can't establish a connection to the server at ws://192.168.0.155:5555/socket/server3.php. $(document).ready(function(){ if(!("WebSocket" in window)){ alert('not available'); }else{ _init(); } }); function _init(){ var websocket; var host = 'ws://192.168.0.155:5555/socket/server3.php'; try{ websocket = new WebSocket(host); websocket.onopen = function(evt){ onOpen(evt); }; websocket.onclose = function(evt) { onClose(evt); }; websocket.onmessage = function(evt) { onMessage(evt); };