Hi all,
Iam trying to receive messages from a websocket server to AppGameKit and back.
i have succesfull made a connection fom a websocket html file to a node server.js.
That works great.
But now i want to use AppGameKit sockets to connect to that same node server.js.
GetSocketConnected() gives a '1' back, but nothing happens on the server side or client side.
code server.js:
const WebSocket = require('ws')
const wss = new WebSocket.Server({ port: 25565 })
wss.on('connection', ws => {
ws.on('message', message => {
console.log('Received message => ' + message)
})
console.log('connectie?');
ws.send('Test message to AGK!')
ws.send('12')
})
AGK client side code:
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "wstest2" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 )
SocketID = ConnectSocket("127.0.0.1", 25565, 3000)
global temp as integer = 0
do
Select GetSocketConnected(SocketID)
Case -1
Print("failed to connect")
END
EndCase
Case 0
Print("trying to connect")
EndCase
Case 1
Print("Connected")
if temp = 0
text as string
test = SendSocketString(SocketID, "test?")
SendSocketInteger(SocketID, 12)
FlushSocket( SocketID )
text = GetSocketString(SocketID)
//print(text)
message(text)
temp = 1
endif
EndCase
EndSelect
Print( ScreenFPS() )
Sync()
loop
So the questions is: How can i send and receive data from and to a node js server?
i surely do something wrong or i miss some important code.
Any help regarding this is very appreciated.
edit: whoops, topic title should be: 'How to send and receive messages from a websocket server?'