Who Knows How To Connect Javascript To Php Server Live Socket Side? See My Code - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Who Knows How To Connect Javascript To Php Server Live Socket Side? See My Code (271 Views)
1 Reply
| Who Knows How To Connect Javascript To Php Server Live Socket Side? See My Code by peterobitinubu(op): 2:36am On Jul 11, 2023 |
who knows how to connect javascript to php server live socket side? this is my connection but it is not working let socket = new WebSocket("ws://203.161.58.199:22" ;var socketOpen = (e) => { $address = '203.161.58.199'; $port = 22; $null = NULL; |
| Re: Who Knows How To Connect Javascript To Php Server Live Socket Side? See My Code by richebony: 7:01am On Jul 11, 2023 |
You didn't specify what the error is being thrown, if it established a connection , or if the client and server have the same origin if the latter is the case Allow CORS ws.on('headers', (headers, request) => { headers.push('Access-Control-Allow-Origin: *'); headers.push('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept'); }); To check if your websocket is even connected on Bootstrap if (ws.readyState === ws.OPEN) { console.log('WebSocket is open '); } else { console.log('WebSocket is closed'); } PS : if you aren't limited by tech specifications I would suggest using Sockets.io ...it offers a lot of abstraction over cross-cutting concerns that might come up when your application scales |
Please, Does Anyone Know How To Connect Javascript To A PHP Socket Server On A L • How To Change Wordpress To Php • How To Use Javascript To Build A Desktop App Using Nw.js • 2 • 3 • 4
_____ • I Need PHP Website Developer In Port Harcourt For Projects • Backend Development Roadmap: Navigating The Digital Backbone
;