Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 41 of 41

Thread: simple soclet communication between 2 PCs

  1. #26
    Junior Member
    Join Date
    Dec 2013
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: simple soclet communication between 2 PCs

    yes - because my main java program operates on an hourly basis and it is NOT receiving a message from Computer 2

    I probably have errors in the code on both sides at the moment but one main problem is that a message is NOT being sent from Computer 2 (Client Socket)

  2. #27
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: simple soclet communication between 2 PCs

    Be sure to close the open socket before trying to open another one.

    Have you tested the code using the local host address? If the code works on one PC then the problem could be with firewalls and routers.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #28
    Junior Member
    Join Date
    Dec 2013
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: simple soclet communication between 2 PCs

    My understanding is that if a message was successfully received by Computer 1, then the socket would be closed

    Thus my prime problem is:- why does the code on Computer 2 (client) not send a message ?

    Bob M

  4. #29
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: simple soclet communication between 2 PCs

    Does the code work on one PC using the local host address?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #30
    Junior Member
    Join Date
    Dec 2013
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: simple soclet communication between 2 PCs

    Client error: (hourly)
    SocketClient exception occurred: java.net.ConnectException: Connection refused: connect

  6. #31
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: simple soclet communication between 2 PCs

    Does the code test ok on the local PC?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #32
    Junior Member
    Join Date
    Dec 2013
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: simple soclet communication between 2 PCs

    I do not understand you...........

    Both PC's are local ?

    Does the calling code on the Client side look OK ?

  8. #33
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: simple soclet communication between 2 PCs

    By local I mean that the server and client programs execute on the same (and only) PC using the localhost IP address: 127.0.0.1

    Does the calling code on the Client side look OK ?
    Hard to say.
    Make a small, complete program that compiles and can be executed for testing.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #34
    Junior Member
    Join Date
    Dec 2013
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: simple soclet communication between 2 PCs

    In the calling code on the Client computer (No.2)
    do I need to replace "localhost" with the IP address of Computer 1 ?

    Bob M

    p.s. have just replaced an ethernet cable - now both computers are on the same network

    --- Update ---

    Client - no error

    Server error: (hourly)
    SocketServer exception occurred: java.net.NullPointerException

    Bob M

  10. #35
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: simple soclet communication between 2 PCs

    java.net.NullPointerException
    You need the full stack trace to see where that exception happened.

    do I need to replace "localhost" with the IP address
    Yes

    Do the programs work with the localhost address when the server and client code are executed on the same PC?
    If you don't understand my answer, don't ignore it, ask a question.

  11. #36
    Junior Member
    Join Date
    Dec 2013
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: simple soclet communication between 2 PCs

    Here is the full stack trace

    2019-06-18 23:00:03 at java.lang.Thread.run(Unknown Source)
    2019-06-18 23:00:03 at com.dukascopy.api.impl.execution.f$a.run(L:926)
    2019-06-18 23:00:03 at com.dukascopy.api.impl.execution.f$a.e(L:904)
    2019-06-18 23:00:03 at java.util.concurrent.FutureTask.run(Unknown Source)
    2019-06-18 23:00:03 at com.dukascopy.api.impl.execution.m.call(L:23)
    2019-06-18 23:00:03 at com.dukascopy.api.impl.execution.m.call(L:63)
    2019-06-18 23:00:03 at com.dukascopy.api.impl.execution.m.cu(L:85)
    2019-06-18 23:00:03 at my_strategies.us_copiosus_GBPAUD_1010.onBar(us_cop iosus_GBPAUD_1010.java:471)
    2019-06-18 23:00:03 at my_strategies.us_copiosus_GBPAUD_1010$SocketServer .start(us_copiosus_GBPAUD_1010.java:1720)
    2019-06-18 23:00:03 java.lang.NullPointerException
    2019-06-18 23:00:03 SocketServer exception occurred: java.lang.NullPointerException
    2019-06-18 22:08:30 Strategy Started: GBP_AUD

    I believe the following calling code from my main java program is incorrect

    // initialise and start our thread
    NewThread t = new NewThread();
    t.start();

    // setup socket connection on new background thread (to receive trading decision from Computer 2)
    try {
    SocketServer server = new SocketServer(9876);
    server.start(); - stack trace points to this line as being in error - null exception
    }
    catch(Exception e) {
    myConsole.getOut().println("SocketServer exception occured: " + e);
    e.printStackTrace();
    }

  12. #37
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: simple soclet communication between 2 PCs

    the full stack trace
    It is missing the first line(s) that gives the type of exception.

    2019-06-18 23:00:03 at my_strategies.us_copiosus_GBPAUD_1010$SocketServer .start(us_copiosus_GBPAUD_1010.java:1720)
    2019-06-18 23:00:03 java.lang.NullPointerException
    What variable on line 1720 has the null value? Backtrack in the code to see why.

    Please answer this question:
    Do the programs work with the localhost address when the server and client code are executed on the same PC?

    I believe the following calling code
    Please wrap ALL posted code in code tags.

    code from my main java program is incorrect
    What do you think is incorrect?
    If you don't understand my answer, don't ignore it, ask a question.

  13. #38
    Junior Member
    Join Date
    Dec 2013
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: simple soclet communication between 2 PCs

    Norm

    The first line is NOT missing

    there is no variable on line 1720

    that line is

    server.start();

  14. #39
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: simple soclet communication between 2 PCs

    there is no variable on line 1720
    that line is
    server.start();
    server is a variable. It should be reference to a class with the method start().

    The first line is NOT missing
    On all exception messages I've seen, the lines starting with at are not on the first line. The first line does not begin with at ...
    If you don't understand my answer, don't ignore it, ask a question.

  15. #40
    Junior Member
    Join Date
    Dec 2013
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: simple soclet communication between 2 PCs

    the stack trace needs to be read from the bottom upwards - see the time stamps

  16. #41
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: simple soclet communication between 2 PCs

    Strange. I've never seen console output in reverse order. Usually the top is the oldest and the bottom the youngest.
    If you don't understand my answer, don't ignore it, ask a question.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. How Accessing PCs in a Domain
    By evaboy in forum Java Networking
    Replies: 1
    Last Post: May 28th, 2017, 11:53 AM
  2. JAVA and communication with RS232
    By wafa22 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 2nd, 2014, 08:38 AM
  3. usb hid about communication
    By serifvatansever in forum Android Development
    Replies: 1
    Last Post: November 2nd, 2013, 08:01 PM
  4. client server communication
    By Brt93yoda in forum Java Theory & Questions
    Replies: 4
    Last Post: September 2nd, 2010, 04:49 PM
  5. communication protocol
    By isaac in forum Java Networking
    Replies: 1
    Last Post: February 5th, 2010, 08:20 AM