Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@

public abstract class JupyterSocket extends ZMQ.Socket {

/**
* Builds a ZeroMQ endpoint for a channel from the connection file properties. For the {@code ipc} transport,
* Jupyter treats {@code ip} as a base path and names each channel socket {@code "{ip}-{port}"}
* (this is what {@code jupyter_client} writes and what frontends connect to).
*/
protected static String formatAddress(String transport, String ip, int port) {
return transport + "://" + ip + ":" + port;
String separator = "ipc".equalsIgnoreCase(transport) ? "-" : ":";
return transport + "://" + ip + separator + port;
}

// Comes from a Python bytestring
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.dflib.jjava.jupyter.channels;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class JupyterSocketTest {

@Test
public void formatAddress_tcp() {
assertEquals("tcp://127.0.0.1:54321", JupyterSocket.formatAddress("tcp", "127.0.0.1", 54321));
}

@Test
public void formatAddress_ipc() {
// Jupyter convention: "ip" is a base path, channel sockets are "{ip}-{port}"
assertEquals("ipc:///tmp/kernel-abc-1", JupyterSocket.formatAddress("ipc", "/tmp/kernel-abc", 1));
}
}
Loading