Skip to main content
Participant
November 3, 2021
Answered

[SDK] Can't receive messages with LrSocket

  • November 3, 2021
  • 1 reply
  • 556 views

Hi!

I need to send messages via sockets to Lr. The communincation between my client and netcat (as a server) goes well, the messages are sent. However, I can't get any messages in Lr. Based on the logs onConnecting, onConnection, onError and onClosed are triggered, but it looks likes onMessage is not. I've replicated this with my client and with netcat as a client.

The lua code is the following:

 

 

LrTasks.startAsyncTask(function()
    		LrFunctionContext.callWithContext( 'socket', function( context )
				local running = true
			    local socket = LrSocket.bind {
			        functionContext = context,
			        plugin = _PLUGIN,
			        port = 19684,
			        mode = 'receive',
			        onMessage = function(socket, message)
			            outputToLog("Message!")
			            --Never happens
			            end,
			        onClosed =  function (socket)
			            outputToLog("Closed")
			            running = false
			            end,
			        onError = function (socket, err)
			            socket:reconnect()
			            outputToLog("Error: " .. err) 
			            end,
			        onConnecting = function( socket, port )
			            outputToLog("Waiting for connection on port " .. port)
			            end,
			        onConnected = function (socket, port)
			            outputToLog("New connection!")
			            end}
			    while running do LrTasks.sleep (0.1) end    
			    socket:close ()
			    end )
			    end )

 

 Do you guys have an idea?

Thanks!

This topic has been closed for replies.
Correct answer Reiep

OK, so I found the solution: all the messages must end with a new line (\n) otherwise they are not processed.

1 reply

ReiepAuthorCorrect answer
Participant
November 3, 2021

OK, so I found the solution: all the messages must end with a new line (\n) otherwise they are not processed.

johnrellis
Legend
November 4, 2021

Glad you sort it out. 

 

That silly requirement was never documented, and Adobe has pretty much stopped maintaining the SDK, so there's little point in filing a bug.

 

If you search this forum for "LrSocket", you can find some previous threads with people discussing their experience, in case you get hung up again.