TCP networking with Max and Java
Hello!
I'm writing a Java application that will receive images processed through Jitter. I was planning to use [jit.net.send] to send the images (https://cycling74.com/sdk/MaxSDK-5.1.1/html/chapter_jit_networking.html).
Prior to getting into the serious stuff, I wanted to test the TCP connection between Max and a simple Java program. I am unable to get Max and Java to communicate using the Max object [mxj net.tcp.send] and a Java Socket. I've tried using UDP and it's working fine so the problem is not a network setting on my computer.
I don't know what I'm doing wrong, so any help would be welcome. Thanks!
Attached is my simple tcp test patch and here is the Java application I used to test:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.Socket;
public class tcpTester {
public static void main(String args[]) {
Socket tcpSocket = null;
String host = "localhost";
int port = 1234;
System.out.println("tcpTester");
while (tcpSocket == null) {
try {
tcpSocket = new Socket(host, port);
System.out.println("Connected!");
if (tcpSocket.getInputStream()==null)
System.out.println("input stream is null");
InputStream inputStream = tcpSocket.getInputStream();
InputStreamReader streamReader = new InputStreamReader(inputStream);
BufferedReader instream = new BufferedReader(streamReader);
String message = instream.readLine();
System.out.println("Got message: " + message);
tcpSocket.close();
} catch (IOException ioe) {
System.out.println("ioe: Unable to connect to host '" + host + "' on port " + port + ".");
//ioe.printStackTrace();
}
}
}
}