Click here to Skip to main content
15,918,003 members
Home / Discussions / Java
   

Java

 
AnswerRe: Relative Sorting Pin
jimakoskx28-Jun-23 23:34
jimakoskx28-Jun-23 23:34 
AnswerRe: Relative Sorting Pin
jimakoskx28-Jun-23 23:54
jimakoskx28-Jun-23 23:54 
QuestionGiven an array arr of size N. Pin
Member 1603793426-Jun-23 6:40
Member 1603793426-Jun-23 6:40 
AnswerRe: Given an array arr of size N. Pin
Victor Nijegorodov26-Jun-23 7:12
Victor Nijegorodov26-Jun-23 7:12 
AnswerRe: Given an array arr of size N. Pin
Richard MacCutchan26-Jun-23 8:18
mveRichard MacCutchan26-Jun-23 8:18 
QuestionHow to make "upload video" in web application ? Pin
Noor Fatima BSSE202111-Mar-23 6:39
Noor Fatima BSSE202111-Mar-23 6:39 
AnswerRe: How to make "upload video" in web application ? Pin
jschell27-Mar-23 7:08
jschell27-Mar-23 7:08 
QuestionClient can't connect to server when client/server are different projects Pin
Valentinor17-Feb-23 20:50
Valentinor17-Feb-23 20:50 
I was doing some Socket tests, and while using localhost everything ran as I wanted. But then I tried to switch it to IP address, and well then things got weird. While the code was in the same class (Code_1 bellow), the simplified test from below was running fine, but as soon as I moved the server code in another project, even another package or class in same package, then when I'm running client code I'm getting java.net.ConnectException: Connection timed out: connect. If when the server is in another project, and for client I'm switching to localhost, then this time it is working. It doesn't want to work when they are in different projects/packages, and the client is using IP address and not localhost, but they work if both are in same project even if client has IP address or localhost.

Code_1
public static void main(String[] args) throws Exception {
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                ServerSocket server = new ServerSocket(port);
                Socket socket = server.accept();
                System.out.println(new ObjectInputStream(socket.getInputStream()).readObject());
                socket.close();
                server.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });
    thread.start();

    Socket socket = new Socket("IP_ADDRESS", port);
    new ObjectOutputStream(socket.getOutputStream()).writeObject("Test");
    socket.close();
}


What is the problem, and what can I do to fix it?
AnswerRe: Client can't connect to server when client/server are different projects Pin
Valentinor17-Feb-23 21:53
Valentinor17-Feb-23 21:53 
GeneralRe: Client can't connect to server when client/server are different projects Pin
englebart26-Apr-23 16:14
professionalenglebart26-Apr-23 16:14 
AnswerRe: Client can't connect to server when client/server are different projects Pin
Richard MacCutchan17-Feb-23 21:58
mveRichard MacCutchan17-Feb-23 21:58 
GeneralRe: Client can't connect to server when client/server are different projects Pin
Valentinor17-Feb-23 22:13
Valentinor17-Feb-23 22:13 
GeneralRe: Client can't connect to server when client/server are different projects Pin
Richard MacCutchan17-Feb-23 22:46
mveRichard MacCutchan17-Feb-23 22:46 
GeneralRe: Client can't connect to server when client/server are different projects Pin
Valentinor17-Feb-23 23:05
Valentinor17-Feb-23 23:05 
Questionfull answer with code pls Pin
Member 159126962-Feb-23 12:06
Member 159126962-Feb-23 12:06 
AnswerRe: full answer with code pls Pin
jschell6-Feb-23 6:21
jschell6-Feb-23 6:21 
AnswerRe: full answer with code pls Pin
Dave Kreskowiak6-Feb-23 6:32
mveDave Kreskowiak6-Feb-23 6:32 
GeneralRe: full answer with code pls Pin
Andre Oosthuizen8-Feb-23 4:30
mveAndre Oosthuizen8-Feb-23 4:30 
AnswerRe: full answer with code pls Pin
Richard MacCutchan6-Feb-23 6:37
mveRichard MacCutchan6-Feb-23 6:37 
AnswerRe: full answer with code pls Pin
Gerry Schmitz6-Feb-23 6:39
mveGerry Schmitz6-Feb-23 6:39 
QuestionUsing JNI without having to add jvm.dll path inside Environment Variables (User or System) Pin
JohnCodding25-Jan-23 20:38
JohnCodding25-Jan-23 20:38 
AnswerRe: Using JNI without having to add jvm.dll path inside Environment Variables (User or System) Pin
Richard MacCutchan25-Jan-23 22:31
mveRichard MacCutchan25-Jan-23 22:31 
GeneralRe: Using JNI without having to add jvm.dll path inside Environment Variables (User or System) Pin
JohnCodding25-Jan-23 22:47
JohnCodding25-Jan-23 22:47 
GeneralRe: Using JNI without having to add jvm.dll path inside Environment Variables (User or System) Pin
Richard MacCutchan26-Jan-23 0:02
mveRichard MacCutchan26-Jan-23 0:02 
GeneralRe: Using JNI without having to add jvm.dll path inside Environment Variables (User or System) Pin
JohnCodding26-Jan-23 0:16
JohnCodding26-Jan-23 0:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.