logo
down
shadow

socket.io switch between localhost & server


socket.io switch between localhost & server

By : Gerardo
Date : October 16 2020, 03:08 PM
this one helps. You could first attempt a connection to the public IP address and, if that fails, then attempt to connect locally. Here's one way to do that:
code :
let socket = io.connect('http://92.12.137.143:1337');
socket.on('connect_error', handleNoConnect);
socket.on('connect_timeout', handleNoConnect);
socket.on('connect', onConnect);

function handleNoConnect() {
    console.log("No connection to http://92.12.137.143:1337");
    socket = io.connect('http://192.168.1.6:1337');
    socket.on('connect_error', handleNoConnect2);
    socket.on('connect_timeout', handleNoConnect2);
    socket.on('connect', onConnect);
}

function handleNoConnect2() {
    console.log("No connection to http://192.168.1.6:1337");
    // decide what to do when you can't connect to either
}

function onConnect() {
    console.log("connected");

    // set other event handlers on a connected socket
    socket.on('disconnect', function() {
        console.log("disconnected");
    });
}
function connect(list) {
    let index = 0;
    return new Promise((resolve, reject) => {
        function next() {
            if (index < list.length) {
                let url = list[index++];
                let doneThis = false;
                let socket = io.connect(url);
                socket.on('connect_error', handleNoConnect);
                socket.on('connect_timeout', handleNoConnect);
                socket.on('connect', () => {
                    // set property on socket object that tells you 
                    //   which URL it connected to
                    socket._url = url;
                    resolve(socket);
                });

                function handleNoConnect() {
                    if (!doneThis) {
                        doneThis = true;
                        console.log("No connection to " + url);
                        // try next item in the list
                        next();
                    }
                }

            } else {
                reject(new Error("No connections succeeded"));
            }
        }
        if (!list || !list.length) {
            reject(new Error("Must pass array of URLs to connect()"));
            return;
        }
        next();
    });
}

connect(['http://92.12.137.143:1337', 'http://192.168.1.6:1337']).then(socket => {
    // connected here
    console.log("connected to " + socket._url);

    // configure event handlers on the connected socket object here
    socket.on('xxx', ...);
}).catch(err => {
    // all connections failed here
    console.log(err);
})


Share : facebook icon twitter icon
Can't establish a connection to the server at ws://localhost:8000/socket/server/startDaemon.php. var socket = new WebSoc

Can't establish a connection to the server at ws://localhost:8000/socket/server/startDaemon.php. var socket = new WebSoc


By : user3127711
Date : March 29 2020, 07:55 AM
With these it helps I solved my error by following code through this link
http://www.flynsarmy.com/2010/05/php-web-socket-chat-application/ and created socketWebSocketTrigger.class.php file for response message where code as
code :
class socketWebSocketTrigger
{   

        function responseMessage($param)
        {
            $a = 'Unknown parameter';

            if($param == 'age'){
                $a = "Oh dear, I'm 152";
            }

            if($param == 'hello'){
                $a = 'hello, how are you?';
            }

            if($param == 'name'){
                $a = 'my name is Mr. websocket';
            }

            if($param == 'today'){
                $a = date('Y-m-d');
            }

            if($param == 'hi'){
                $a = 'hi there';
            }

            return $a;

        }

}
 public function send($client, $msg){
        $this->say("> ".$msg);
        $messageRequest = json_decode($msg,true);

            // $action=$messageRequest[0];
            $action = 'responseMessage';
            $param  = $messageRequest[1]['data'];
        if( method_exists('socketWebSocketTrigger',$action) ){
                                $response = socketWebSocketTrigger::$action($param);
                            }
            $msg = json_encode(
                array(                      
                'message',
                    array('data' => $response)
                )
            );

            $msg = $this->wrap($msg);

        socket_write($client, $msg, strlen($msg));
    }
How to use socket.io to communicate with another server when the actual page is being served by a localhost server?

How to use socket.io to communicate with another server when the actual page is being served by a localhost server?


By : user4500413
Date : March 29 2020, 07:55 AM
With these it helps I'm serving my page through localhost (XAMPP, Apache), and on my friend's physical server I run a node.js server that is used for communication with the page (a game). , Include a script tag in your page:
code :
<script src="http://[YOUR IP]:1235/socket.io/socket.io.js">
var socket = io.connect("http://[YOUR IP]:1235");

socket.emit("start", "LET'S GO!");
php socket server works only on localhost but not live server

php socket server works only on localhost but not live server


By : Kateryna Sidorenko
Date : March 29 2020, 07:55 AM
Hope that helps After some research i found that The code is correct Godaddy does not open custom ports. The code does not work because have a different security policy localhost than GoDaddy (or other hosting website).
Running a socket.io server in a real live server, instead of localhost?

Running a socket.io server in a real live server, instead of localhost?


By : kun0
Date : March 29 2020, 07:55 AM
To fix the issue you can do You can solve your problem through nginix( A reverse proxy server). Nginx have .conf file which contains the server realted configuration.
code :
server { listen 3000; server_name io.yourhost.com; }
Sudo service nginx start
Can't connect socket.io node server to react frontend. "POST http://localhost:3000/socket.io/?EIO=3&transport=p

Can't connect socket.io node server to react frontend. "POST http://localhost:3000/socket.io/?EIO=3&transport=p


By : user3092702
Date : March 29 2020, 07:55 AM
will help you You need to use the http library instead of the https one.
server.listen(3500) does not support https. If for some reason you do need to use it, you can reference this answer.
code :
import openSocket from "socket.io-client";
const hostURL = "http://localhost:3500";
const socket = openSocket()
import openSocket from "socket.io-client";
const hostURL = "http://localhost:3500";
const socket = openSocket(hostURL)
Related Posts Related Posts :
  • Quotation Mark Problems In Word 2013
  • Creating a “Related pages” view which also excludes the current node in Drupal 8
  • HapiJS and Sequelize without Sequelize CLI
  • Reference third party dlls in aspnet core app on top of net452 framework
  • Understanding Slowly Changing Dimension Type 2
  • Subnavigation with title of parent and custom image - TypoScript
  • Grand Total Issue in Cross Table of Spotfire
  • Jenkins Pipeline Plugin don't display script text area
  • Where is NodeMCU getting ip address from?
  • DB2 restore command fails on Windows 10
  • Liferay freemarker list tag - Velocity counterpart
  • How to go about deep mock or stub with Spock?
  • Apache Camel - Servlet Component - is binding path variables possible?
  • Looping through metafields in shopify
  • Wrong sequence assign to delivery order [ Odoo 9.0 ]
  • Search on worklist does not work in SAPUI5 Fiori Template Application
  • Get OAuth2AccessToken additional information in my controller class
  • Papyrus 2.0.1 installation fail on eclipse neon (Release 4.6.1)
  • How can I run my cron every 2 hours everyday which should starts from 12.30pm?
  • Streaming response in Feathers
  • eBay API in Perl - can't use SetShipmentTrackingInfoRequest to update tracking information
  • How to prevent joining values in Row Group (column) of Crosstab?
  • Add a site on Caddy Web Server without restart
  • Inner Join rowset from flat file and SQL
  • Hide "Confirm Sale" button in Sale Order form view in Odoo 9
  • x3d blending textures transparent
  • Arbitrary response content types in Feathers
  • Problems to POST chaincode (smart contract) to hyperledger-fabric using API
  • ICE connectivity check
  • Nightwatch - Meaning of WaitForElementVisible and WaitForElementPresent
  • Request goes to each middleware laravel 5.2
  • Hybris setup for multiple projects
  • Handling input data undefined error
  • How to Merge files from previous revision number to tip in mercurial?
  • SonarQube Line Coverage Rule in Preview Mode
  • How to update item conditionally with branch in RethinkDB
  • Generate XML-Report for xUnit using Visual Studio Runner
  • Creating Hashtags in swift
  • How to use the Amazon AWS CLI to update a DynamoDB global secondary index?
  • Error in opennebula installation
  • Perform a drag and drop in serenity-js
  • How to test OpenIm (ForgeRock) Request on Postman?
  • How to generate mock server for pact consumer from contract json file?
  • How Can i add the customized section to home page in broadleaf
  • Swagger With Karaf Integration
  • Conditionally flag rows from one group based on data from another group
  • Regular Expression, Match ccurrenced text
  • jspdf first PDF page is blank
  • Trying to add Facebook Get Started button
  • Load JSON into Firestore - data types
  • Server sends Welcome message more than once using select()
  • Create something of similar to Watson Virtual Agents
  • Limiting the results of drop-down in Google Sheets
  • Why does gcrypt say to recalculate the coefficient of an RSA key when converting from SSL format to gcrypt?
  • Standard Deviation of Principal Components
  • MediaWiki: Convert seconds to HH:MM:SS
  • Char to String conversion Ada
  • Aurelia: translate + parameter comes from value converter
  • Upload same name files to google cloud storage then download them with original names
  • Control Graphviz arrows direction
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com