You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I like your project very much.
Recently I switched to vscode to develop my JDK 22 -based program. I found that this project use the Java Compiler API , which support the unpublished JDK (like 22).
I added the extraCompilerArgs option to allow pass -enable-preview and -source 22 when compiling.
public class Server {
public static void main(String[] args) {
try {
// Create a server socket
ServerSocket serverSocket = new ServerSocket(1256);
System.out.println("Server is running...");
while (true) {
// Accept a client connection
Socket clientSocket = serverSocket.accept();
System.out.println("Connection from: " + clientSocket.getInetAddress().getHostAddress());
// Create input and output streams for the client socket
BufferedReader input = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
PrintWriter output = new PrintWriter(clientSocket.getOutputStream(), true);
String distance;
while ((distance = input.readLine()) != null) {
if (distance.equalsIgnoreCase("bye")) {
break;
}
try {
// Convert distance to meters
int kilometers = Integer.parseInt(distance);
int meters = kilometers * 1000;
// Send the converted distance back to the client
output.println(String.valueOf(meters));
} catch (NumberFormatException e) {
// Handle invalid input from the client
output.println("Invalid input. Please send a valid distance in kilometers.");
}
}
// Close the client socket
clientSocket.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public class Client {
public static void main(String[] args) {
try {
// Create a socket and connect to the server
Socket socket = new Socket("localhost", 1256);
System.out.println("Connected to server: " + socket.getInetAddress().getHostAddress());
// Create input and output streams for the socket
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter output = new PrintWriter(socket.getOutputStream(), true);
BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in));
String distance;
while ((distance = userInput.readLine()) != null) {
// Send the distance to the server
output.println(distance);
if (distance.equalsIgnoreCase("bye")) {
break;
}
// Receive the response from the server
String response = input.readLine();
// Display the response
System.out.println("Server response: " + response);
}
// Close the socket
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello,
I like your project very much.
Recently I switched to vscode to develop my JDK 22 -based program. I found that this project use the Java Compiler API , which support the unpublished JDK (like 22).
I added the
extraCompilerArgsoption to allow pass-enable-previewand-source 22when compiling.