Created
May 8, 2013 16:43
-
-
Save NicolasZanotti/5541764 to your computer and use it in GitHub Desktop.
This is a test for running InDesign as a simple socket server. It can be connected to using Node. Both pass messages back and forth before Node closes the connection. Run the server.jsx file using the ExtendScript Toolkit (included with Adobe Creative Suite). Then run the client.js using Node.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var net = require('net'); | |
var client = net.connect({port: 8000}, function() { | |
console.log('Client connected.'); | |
client.write('Hello from Node!'); | |
}); | |
client.on('data', function(data) { | |
console.log(data.toString()); | |
client.end(); | |
}); | |
client.on('end', function() { | |
console.log('Client disconnected.'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#target InDesign | |
var socket, connection, text; | |
function main() { | |
socket = new Socket(); | |
if (socket.listen(8000)) { | |
$.writeln("Server listening on port 8000"); | |
while (true) { | |
connection = socket.poll(); | |
if (connection !== null) { | |
$.writeln("New connection from " + connection.host.toString() + "."); | |
connection.writeln ("Hello from InDesign!"); | |
message(connection); | |
connection.close(); | |
connection = null; | |
$.writeln("Connection closed."); | |
} | |
$.sleep(100); | |
} | |
} | |
} | |
function message(connection) { | |
connection.timeout=1000; | |
while (true) { | |
if (!connection.connected) return; | |
text = connection.read(); | |
connection.write("Client said: " + text); | |
$.writeln(text); | |
$.sleep(100); | |
} | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Nicolas.
I'm trying to create a connection to the indesign server in jsx which is at IP 10.10.1.1 with port 18777. Your script for jsx doesn't seem to have a host parameter in it or am I missing something? Basically I'm trying to move all my PDFing to the server but so far I didn't succeed because no matter what, it doesn't want to recognize server paths. I.e. it works fine locally but when I enter full server path, it says error 48 cannot find folder. The folder is obviously there. Could you help me with this.
MIchael