DEBUG:SCRIPT: Error: 'Websocket closing for localhost (WSLAY_ERR_CALLBACK_FAILURE

hello all ,
Im trying very simple websocket test where in defold i have button when on click it send to websocket server open connection and the server in return send back 2 strings .
using on server side simple java WebFlux ws server very simple …
but looks like it try’s to connect after the server is closed or something and keep getting :

ERROR:WEBSOCKET: Websocket poll error: WSLAY_ERR_CALLBACK_FAILURE
WARNING:WEBSOCKET: STATUS: 'Websocket closing for localhost (WSLAY_ERR_CALLBACK_FAILURE)'  len: 60
WARNING:WEBSOCKET: STATE_CONNECTED -> STATE_DISCONNECTED
DEBUG:SCRIPT: Error: 'Websocket closing for localhost (WSLAY_ERR_CALLBACK_FAILURE)'
DEBUG:SCRIPT: Disconnected: userdata: 0x01ca039b0b30
WARNING:WEBSOCKET: DestroyConnection: 000001CA039B0B30

This is the code from my defold client :

local networkmaneger = require ("main/scripts.network_maneger")



function init(self)

	msg.post(".","acquire_input_focus")
	msg.post("#","show_level_select")
	self.active = false

	self.url = networkmaneger.WSURL
	print(self.url)
	
	
end



function on_message(self, message_id, message, sender)
	if message_id == hash("show_level_select") then 
		msg.post("#","enable")
		self.active = true
	elseif message_id == hash("hide_level_select") then 
		msg.post("#","disable")
		self.active = false
	end
end

function on_input(self, action_id, action)
	if action_id == hash("touch") and action.pressed and self.active then 
		print("button pressed1111")
		local params = {}
		self.connection = websocket.connect(self.url, params, networkmaneger.websocket_callback)
		return true
	end
	 
end
  function finalize(self)
	if self.connection ~= nil then
		websocket.disconnect(self.connection)
	end
end

the main/scripts.network_maneger:

local M = {}

M.WSURL = "ws://localhost:8001/test"


    function M.websocket_callback(self, conn, data)
    	if data.event == websocket.EVENT_DISCONNECTED then
    		print("Disconnected: " .. tostring(conn))
    		self.connection = nil
    		--update_gui(self)
    	elseif data.event == websocket.EVENT_CONNECTED then
    		--update_gui(self)
    		print("Connected: " .. tostring(conn))
    	elseif data.event == websocket.EVENT_ERROR then
    		print("Error: '" .. tostring(data.message) .. "'")
    		if data.handshake_response then
    			print("Handshake response status: '" .. tostring(data.handshake_response.status) .. "'")
    			for key, value in pairs(data.handshake_response.headers) do
    				print("Handshake response header: '" .. key .. ": " .. value .. "'")
    			end
    			print("Handshake response body: '" .. tostring(data.handshake_response.response) .. "'")
    		end
    	elseif data.event == websocket.EVENT_MESSAGE then
    		print("Receiving: '" .. tostring(data.message) .. "'")
    	end
    end


    return M

And this is the log , it does receive the data from the server which is : “XXX2”,“YYY1”
this is the full log on :

INFO:DLIB: Log server started on port 64689
INFO:ENGINE: Target listening with name: MEIRYANO-PC - fe80::1ee3:2087:9e5f:ba26 - Windows
INFO:ENGINE: Engine service started on port 64690
INFO:GRAPHICS: Installed graphics device 'ADAPTER_FAMILY_OPENGL'
INFO:ENGINE: Defold Engine 1.6.3 (37a4a85)
INFO:WEBSOCKET: dmWebSocket::g_DebugWebSocket == 2
INFO:DLIB: Initialized Remotery (ws://127.0.0.1:17815/rmt)
INFO:ENGINE: Loading data from: build/default
INFO:WEBSOCKET: Registered websocket extension
INFO:ENGINE: Initialised sound device 'default'
DEBUG:SCRIPT: ws://localhost:8001/test
INFO:DLIB: SSDP: Started on address 10.100.102.13
INFO:DLIB: SSDP: Started on address 169.254.72.227
INFO:DLIB: SSDP: Started on address 172.27.96.1
INFO:DLIB: SSDP: Started on address 192.168.176.1
DEBUG:SCRIPT: button pressed1111
WARNING:WEBSOCKET: STATE_CREATE -> STATE_CONNECTING
WARNING:WEBSOCKET: STATE_CONNECTING -> STATE_HANDSHAKE_WRITE
WARNING:WEBSOCKET: Sent buffer: 'GET ' 4 bytes
WARNING:WEBSOCKET: Sent buffer: '/test' 5 bytes
WARNING:WEBSOCKET: Sent buffer: ' HTTP/1.1\r\n' 11 bytes
WARNING:WEBSOCKET: Sent buffer: 'Host: ' 6 bytes
WARNING:WEBSOCKET: Sent buffer: 'localhost' 9 bytes
WARNING:WEBSOCKET: Sent buffer: ':8001' 5 bytes
WARNING:WEBSOCKET: Sent buffer: '\r\n' 2 bytes
WARNING:WEBSOCKET: Sent buffer: 'Upgrade: websocket\r\n' 20 bytes
WARNING:WEBSOCKET: Sent buffer: 'Connection: Upgrade\r\n' 21 bytes
WARNING:WEBSOCKET: Sent buffer: 'Sec-WebSocket-Key: ' 19 bytes
WARNING:WEBSOCKET: Sent buffer: 'o6UW72QEfa7LuqURL1vcSQ==' 24 bytes
WARNING:WEBSOCKET: Sent buffer: '\r\n' 2 bytes
WARNING:WEBSOCKET: Sent buffer: 'Sec-WebSocket-Version: 13\r\n' 27 bytes
WARNING:WEBSOCKET: Sent buffer: '\r\n' 2 bytes
WARNING:WEBSOCKET: STATE_HANDSHAKE_WRITE -> STATE_HANDSHAKE_READ
WARNING:WEBSOCKET: Waiting for socket to be available for reading
WARNING:WEBSOCKET: Received bytes: 'HTTP/1.1 101 Switching Protocols\r\nupgrade: websocket\r\nconnection: upgrade\r\nsec-websocket-accept: lGKE2T8p9CL1oE7YwKSGEx+TW7Q=\r\n\r\n' 129 bytes
WARNING:WEBSOCKET: Secret key (base64): o6UW72QEfa7LuqURL1vcSQ==
WARNING:WEBSOCKET: Secret key + RFC_MAGIC: o6UW72QEfa7LuqURL1vcSQ==258EAFA5-E914-47DA-95CA-C5AB0DC85B11
WARNING:WEBSOCKET: Hashed key (sha1): '\94b\84\d9?)\f4"\f5\a0N\d8\c0\a4\86\13\1f\93[\b4' 20 bytes
WARNING:WEBSOCKET: Client key (base64): lGKE2T8p9CL1oE7YwKSGEx+TW7Q=
WARNING:WEBSOCKET: Server key (base64): lGKE2T8p9CL1oE7YwKSGEx+TW7Q=
WARNING:WEBSOCKET: STATE_HANDSHAKE_READ -> STATE_CONNECTED
DEBUG:SCRIPT: Connected: userdata: 0x01ca039b0b30
WARNING:WEBSOCKET: Received bytes: '\81\04XXX2\81\04YYY1\88\05\03\e8Bye' 19 bytes
WARNING:WEBSOCKET: PushMessage 'XXX2' 4 bytes
WARNING:WEBSOCKET: PushMessage 'YYY1' 4 bytes
WARNING:WEBSOCKET: PushMessage 'Server closing (1000). Reason: 'Bye'' 36 bytes
WARNING:WEBSOCKET: Server closing (1000). Reason: 'Bye'
WARNING:WEBSOCKET: Sent buffer: '\88\85D\b4\03\d8' 6 bytes
ERROR:WEBSOCKET: Websocket poll error: WSLAY_ERR_CALLBACK_FAILURE
WARNING:WEBSOCKET: STATUS: 'Websocket closing for localhost (WSLAY_ERR_CALLBACK_FAILURE)'  len: 60
WARNING:WEBSOCKET: STATE_CONNECTED -> STATE_DISCONNECTED
DEBUG:SCRIPT: Error: 'Websocket closing for localhost (WSLAY_ERR_CALLBACK_FAILURE)'
DEBUG:SCRIPT: Disconnected: userdata: 0x01ca039b0b30
WARNING:WEBSOCKET: DestroyConnection: 000001CA039B0B30

Not sure if it matters, but the lifecycle function is named final not finalize.

It’s hard to say what else could be wrong.

What makes you think this? The full log seems to show that you receive XXX2 and YYY1 and then the server closes.

2 Likes

Tnx
i managed to connect problem was in the server impl but now i have many other questions which i will ask in different thread

1 Like