Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compiler extra args configuration. #275

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SnowNF
Copy link

@SnowNF SnowNF commented Oct 13, 2023

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.

@Mohammedalshamiri
Copy link

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

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();
    }
}

}

@Mohammedalshamiri
Copy link

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

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();
    }
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants