Click here to Skip to main content
15,867,308 members
Home / Discussions / Java
   

Java

 
AnswerRe: Operator precedence Pin
Richard Deeming11-Jul-23 3:30
mveRichard Deeming11-Jul-23 3:30 
GeneralRe: Operator precedence Pin
darek2902198812-Jul-23 5:44
darek2902198812-Jul-23 5:44 
GeneralRe: Operator precedence Pin
jeron112-Jul-23 6:15
jeron112-Jul-23 6:15 
AnswerRe: Operator precedence Pin
Richard MacCutchan11-Jul-23 5:24
mveRichard MacCutchan11-Jul-23 5:24 
GeneralRe: Operator precedence Pin
darek2902198812-Jul-23 5:46
darek2902198812-Jul-23 5:46 
QuestionRe: Operator precedence Pin
Richard MacCutchan12-Jul-23 6:15
mveRichard MacCutchan12-Jul-23 6:15 
AnswerRe: Operator precedence Pin
Andre Oosthuizen14-Jul-23 1:36
mveAndre Oosthuizen14-Jul-23 1:36 
GeneralRe: Operator precedence Pin
Richard MacCutchan14-Jul-23 1:52
mveRichard MacCutchan14-Jul-23 1:52 
QuestionSign a PDF document in PAdeS format using a CNS (National Services Card) or a SmartCard. Pin
Antonio20238-Jul-23 19:45
Antonio20238-Jul-23 19:45 
QuestionRelative Sorting Pin
Harriet Muduwa26-Jun-23 6:42
Harriet Muduwa26-Jun-23 6:42 
AnswerRe: Relative Sorting Pin
Pete O'Hanlon26-Jun-23 7:12
subeditorPete O'Hanlon26-Jun-23 7:12 
AnswerRe: Relative Sorting Pin
Victor Nijegorodov26-Jun-23 7:13
Victor Nijegorodov26-Jun-23 7:13 
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 

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.