Send data to socket from Java Card
Posted: Thu Dec 30, 2021 7:01 am
Trying to build solution that allows my Java Card send data via socket. Can Java Card communicate via TCP in general? I have function that can run in Java and trying to convert it to Java Card. I know String is not available in Java Card. What other things I should consider about?
Code: Select all
public void sendSocket()
{
String hostname = "localhost";
int port = 6789;
Socket clientSocket = null;
DataOutputStream os = null;
BufferedReader is = null;
try {
clientSocket = new Socket(hostname, port);
os = new DataOutputStream(clientSocket.getOutputStream());
is = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
} catch (UnknownHostException e) {
System.err.println("Don't know about host: " + hostname);
} catch (IOException e) {
System.err.println("Couldn't get I/O for the connection to: " + hostname);
}
if (clientSocket == null || os == null || is == null) {
System.err.println( "Something is wrong. One variable is null." );
return;
}
try {
os.writeBytes( "aaa" );
os.close();
is.close();
clientSocket.close();
} catch (UnknownHostException e) {
System.err.println("Trying to connect to unknown host: " + e);
} catch (IOException e) {
System.err.println("IOException: " + e);
}
}