I want to write a string to a socket server in java in bytes, then receive the answer (a known length of bytes).
I have looked around and there are many tutorials, but I can't seem to find a specific function to handle the bytes, also, I don't seem to be able to perform functions on out. This stays red underlined.
import java.io.*;
import java.net.Socket;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class SocketTest {
public static void main(String [] args) throws IOException {
String hostName = "localhost";
int portNumber = 10000;
try (
//open a socket
Socket clientSocket = new Socket(hostName, portNumber);
BufferedReader in = new BufferedReader( new InputStreamReader(clientSocket.getInputStream()));
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
) {
System.out.print("Something went wrong");
}
}
try {
out.XXX; //can't seem to execute any function on this.
} catch (Exception e) {
e.printStackTrace();
}