B4A Library WebSocket Client Library

Status
Not open for further replies.

LucaMs

Expert
Licensed User
Longtime User
I'm re-reading this post.

The two server's routines have different scope!
The first, RunOnClient_NewNickOK, is private, the other is public.

The second is ran from a Module in which it is declared a map that contains the private rooms.

Maybe it will be sufficient to use CallSubDelayed, as in the Chatroom, but I can not understand why.


[P.S. using CallSubDelayed does not solve]
 
Last edited:

Reids

Member
Licensed User
Longtime User
Hello, I tried to create simple echo server, but client in basic4android cannot raise event when message received, web based client is received the message
what event for receiving the message? doc only say this lib only has 3 event

Connected
Closed (Reason As String)
TextMessage (Message As String)

but Onmessage does not have event, I also tried to use method as mentioned here
here the code
B4X:
Sub Timer1_Tick
'This method will raise the event on the device
   ws.RunFunction("ServerTime", Array As Object(DateTime.Time(DateTime.Now)))
   ws.Flush


but ws doesn't have ws.RunFunction

Thank You


EDITED:
Nevermind accidentially already found it

shuld call event manualy by
CallSub2(CallBack, "ws_TextMessage" & "_" & "onmessage", params)
 
Last edited:

Douglas Farias

Expert
Licensed User
Longtime User
1° its possible to connect multiple devices at same time at server?
2° all to list(Log) connected IPS,DEVICES on the server
3° its possible to close a connection for one ip?

All this questions is for a online game, the first its to know if can i use this to make a game online.
the second is to know how many users is playing my game, and the 3° its to know if can i ban a bad user from my gameserver.

thx
 

Reids

Member
Licensed User
Longtime User
Hello we are on same boat, the based thing that I achieve so far is :
1.yes it possible, it is possible to connect multiple devices at the same time at the server
2.yes it possible, first you need to send parameter about ip session and device info thorough the header, after that server can read that info and save it as log
3.yes it possible, as I metioned above, all device information can be send over the header in handshake, just search specified ip then terminate it (server side code)

I also tried to developed online game with basic4android, but there are so many trouble
eg for mmorpg type game:
1. it is need hardcoded on server side to update only nearest character with player character
2. I recommended use native php code to server websocket so many example out there
3. you can make simple chatting apps first, if you can achieve that, it would be easier to achieve making online game
 

javiman6969

Member
Licensed User
Longtime User
Hi, Erel.

I'm trying to test this library, but can not I connect to a single server using node.js socket.io
I returned the message server disconnection "websockets connection lost" after clicking "Connect"

You could help me with some example of using connection with socket.io?

Thanks!!
 

javiman6969

Member
Licensed User
Longtime User
This server is in local network.
Using a server with node.js socket.io

A very basic code, to test the connection.
From a web client with javascript connects perfectly.


var io = require('socket.io').listen(8889); // server listens for socket.io communication at port 8889
//io.set('log level', 1); // disables debugging. this is optional. you may remove it if desired.

/io.sockets.on('connection', function (socket) {

console.log('receiving attempt to connect...');


socket.emit('log', { data: 'server connected' });


socket.on('commands', function (data) {

console.log(data);
Proccess_Commands(data);

});

socket.on('log', function (data) {

console.log(data);


});


socket.on('disconnect', function () {
console.log('disconnected from client');
});
});
 

javiman6969

Member
Licensed User
Longtime User
socket.io may support other protocols as well as WebSocket.

You can easily create a WebSocket server with B4J and test it.

Hi Erel
Yes, it is true, but the device where the server runs is an Arduino Yun (Linux: Linino) and I need to be a server with socket.io and node.js
There would be some way to make it work with that?
 

TAK

Member
Licensed User
Longtime User
Hello,
sorry, i have some beginner questions.
What is "Sub WebSocket_Connected" doing? Why do we need a timer? And why do we need StartMessageLoop? What is StartMessageLoop for a function?

Thx
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…