[Solved] Node.js : Attempting to connect

Just starting out? Need help? Post your questions and find answers here.
falsam
Posts: 280
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

[Solved] Node.js : Attempting to connect

Post by falsam »

I'm trying to connect to an existing chat server with SpiderBasic.( http://purebasic.chat )

■ My first test with SpiderBasic is to log in and get a nickname

Code: Select all

Global username.s

!require(["https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"], 
! function(value) {

    ;Connect to server
    Debug "Connection in progress ..."
!   var socket = io.connect('http://109.13.115.206:6832', {'forceNew':true });
  
    ;Server emit a custom event 'setnewguest'
!   socket.on('setnewguest', function(username) {
!   v_username = username
      Debug "Welcome. Your nickname is " + username
!   })
  
  
! }
!);   
 
Unfortunately it does not work. The console says
Console wrote:Uncaught ReferenceError: io is not defined
■ The same code encoded with javascript works

Code: Select all

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>Test Socket.io</title>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"></script>
    </head>
 
    <body>
		<h5>Welcome</h5>
		<div id="username"></div>
		
        <script>
			// Connect to server
            var socket = io.connect('http://109.13.115.206:6832', {'forceNew':true });
			
			//Server emit a custom event 'setnewguest' 
			socket.on('setnewguest', function (data) {
				document.getElementById("username").innerHTML = "Your nickname is " + data;
			})
        </script>
    </body>
</html>
Demo : http://purebasic.chat/test.html


These two codes attempt to connect to a test server. (Not on the operating server)

I hope you will help me to solve this problem. Thank you.
Last edited by falsam on Thu Aug 10, 2017 5:38 pm, edited 3 times in total.

➽ Windows 11 - JDK 1.8 - SB 2.40 - Android 13
http://falsam.com

Sorry for my poor english
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Node.js : Attempting to connect

Post by Peter »

Hello falsam,

change:

Code: Select all

!require(["https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"], 
!  function(result) {
[...]
to:

Code: Select all

!require(["https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"], 
!  function(io) {
[...]
Greetings ... Peter
falsam
Posts: 280
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

Re: Node.js : Attempting to connect

Post by falsam »

Thank very much Peter. I appreciate, I would never have found this solution.

➽ Windows 11 - JDK 1.8 - SB 2.40 - Android 13
http://falsam.com

Sorry for my poor english
Post Reply