₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,344,197 members, 8,510,618 topics. Date: Friday, 30 October 2026 at 05:33 PM

Toggle theme

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 (297 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"wink;

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
1 Reply

Please, Does Anyone Know How To Connect Javascript To A PHP Socket Server On A L • This Php Server Remote Addr Is Giving Me Different Device Ip Address • How To Change Wordpress To Php • 2 • 3 • 4

Best Company For Your Software Development Services • Become A Full-stack Developer If You Live In Ibadan • Hrmszol - HRMS & Payroll Script