Skip to content

Commit

Permalink
fix(debugging): Change default debugging port to 18182
Browse files Browse the repository at this point in the history
The reason for this change is that due to the new logic
of never closing it, any application with ios-runtime 4.1
or later could permanently take it and prevent apps with
an older runtime version from being debugged. We still
prefer to have a default port for easier local development
using `debugger-proxy.js`
  • Loading branch information
mbektchiev committed Apr 23, 2018
1 parent a130bd1 commit 6781d25
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ - (instancetype)initWithSocketPath:(NSString*)socketPath readHandler:(InspectorR
communicationSocket = socket(PF_INET, SOCK_STREAM, 0);

struct sockaddr_in addr = {
sizeof(addr), AF_INET, htons(18181), { INADDR_ANY }, { 0 }
sizeof(addr), AF_INET, htons(18182), { INADDR_ANY }, { 0 }
};

connected = setupConnection((const struct sockaddr*)&addr, sizeof(addr));
Expand Down
2 changes: 1 addition & 1 deletion src/debugging/TNSDebugging.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ TNSCreateInspectorServer(TNSInspectorFrontendConnectedHandler connectedHandler,
setsockopt(listenSocket, SOL_SOCKET, SO_REUSEADDR, &so_reuseaddr,
sizeof(so_reuseaddr));
struct sockaddr_in addr = {
sizeof(addr), AF_INET, htons(18181), { INADDR_ANY }, { 0 }
sizeof(addr), AF_INET, htons(18182), { INADDR_ANY }, { 0 }
};

if (bind(listenSocket, (const struct sockaddr*)&addr, sizeof(addr)) != 0) {
Expand Down
74 changes: 37 additions & 37 deletions src/debugging/debugger-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ var stream = require("stream");

util.inherits(PacketStream, stream.Transform);
function PacketStream(opts) {
stream.Transform.call(this, opts);
stream.Transform.call(this, opts);
}

PacketStream.prototype._transform = function (packet, encoding, done) {
PacketStream.prototype._transform = function(packet, encoding, done) {
while (packet.length > 0) {
if (!this.buffer) {
// read length
Expand All @@ -32,41 +32,41 @@ PacketStream.prototype._transform = function (packet, encoding, done) {
};

var server = ws.createServer({
port: 8080
port: 8080
});
server.on("connection", function(webSocket) {
console.info("Frontend client connected.");

var deviceSocket = net.connect(18181);
var packets = new PacketStream();
deviceSocket.pipe(packets);

packets.on("data", function (buffer) {
//console.log("DEVICE " + buffer.toString("utf8"));
webSocket.send(buffer.toString("utf16le"), function (error) {
if (error) {
console.log("ERROR " + error);
process.exit(0);
}
});
});

webSocket.on("message", function (message, flags) {
//console.log("FRONTEND " + message);
var length = Buffer.byteLength(message, "utf16le");
var payload = new Buffer(length + 4);
payload.writeInt32BE(length, 0);
payload.write(message, 4, length, "utf16le");
deviceSocket.write(payload);
});

deviceSocket.on("end", function() {
console.info("Backend socket closed!");
process.exit(0);
});
console.info("Frontend client connected.");

webSocket.on("close", function() {
console.info('Frontend socket closed!');
process.exit(0);
});
});
var deviceSocket = net.connect(18182);
var packets = new PacketStream();
deviceSocket.pipe(packets);

packets.on("data", function(buffer) {
//console.log("DEVICE " + buffer.toString("utf8"));
webSocket.send(buffer.toString("utf16le"), function(error) {
if (error) {
console.log("ERROR " + error);
process.exit(0);
}
});
});

webSocket.on("message", function(message, flags) {
//console.log("FRONTEND " + message);
var length = Buffer.byteLength(message, "utf16le");
var payload = new Buffer(length + 4);
payload.writeInt32BE(length, 0);
payload.write(message, 4, length, "utf16le");
deviceSocket.write(payload);
});

deviceSocket.on("end", function() {
console.info("Backend socket closed!");
process.exit(0);
});

webSocket.on("close", function() {
console.info('Frontend socket closed!');
process.exit(0);
});
});

0 comments on commit 6781d25

Please sign in to comment.