₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,053 members, 8,420,072 topics. Date: Thursday, 04 June 2026 at 10:45 AM

Toggle theme

Who Knows How To Connect Javascript To Php Server Live Socket Side? See My Code - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingWho 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"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 LHow To Change Wordpress To PhpHow To Use Javascript To Build A Desktop App Using Nw.js234

_____I Need PHP Website Developer In Port Harcourt For ProjectsBackend Development Roadmap: Navigating The Digital Backbone