Skip to content

Sockets

Oddbjørn Bakke edited this page May 9, 2021 · 7 revisions

Plugin:

A plugin connects to port 12136 to communicate with TouchPortal.

From version 2.3 of TouchPortal, the messages can be UTF8 (without BOM / UTF8 Identifier), before that it used standard ASCII.
A message must end with a line shift to indicate that it's finished.

All you need to get started to write your own SDK, is this:

var ipAddress = IPAddress.Parse("127.0.0.1");
var socketAddress = new IPEndPoint(ipAddress, 12136);

var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(socketAddress);

var encoder = new UTF8Encoding(false); //false: Without BOM

var streamWriter = new StreamWriter(new NetworkStream(socket), encoder) { AutoFlush = true };
var streamReader = new StreamReader(new NetworkStream(socket), encoder);

streamWriter.WriteLine("{\"type\":\"pair\", \"id\":\"TouchPortalSDK.Sample\"}"); //Replace with correct installed plugin id from entry.tp

var message = streamReader.ReadLine();
Console.WriteLine(message);

The next step would be to create a listener thread with the streamReader, and react upon messages/events from TouchPortal. Commands are sent like in this example, with the streamWriter.

Other ports:

The Android or iOS device will by default use port 12134 (device to PC) and 12135 (PC to device).

Clone this wiki locally