Results 1 to 4 of 4
  1. #1
    Bob M is offline Member
    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0

    Default Socket Client code - not working yet!

    Hi

    The following is code I have currently

    I don't get any errors posted but nothing is happening

    I call it with the following line:
    SocketClient client = new SocketClient();
    Java Code:
    *******************************************
    /**
         * This class implements java socket client
         *
         */
        public class SocketClient {
            public SocketClient() {
            }
            public final void run(String[] args) throws UnknownHostException, IOException, ClassNotFoundException, InterruptedException {
     
                // get Computer 1 (server) IP address
                InetAddress host = (InetAddress.getByName("10.1.1.2"));
                Socket socket = null;
                ObjectOutputStream oos = null;
                ObjectInputStream ois = null;
                // establish socket connection to server
                socket = new Socket(host.getHostName(), 9875);
                // write to socket using ObjectOutputStream
                oos = new ObjectOutputStream(socket.getOutputStream());
                // Socket
                System.out.println("Sending request to Socket Server");
                oos.writeObject("USDJPY" + Trading_Decision_2);
                // read the server response message
                ois = new ObjectInputStream(socket.getInputStream());
                String message = (String) ois.readObject();
                System.out.println("Message: " + message);
                // close resources
                ois.close();
                oos.close();
                Thread.sleep(100);
            }
        } // end of SocketClient
    *********************************************

    Any suggestions most welcome :)
    Last edited by Norm; 07-17-2019 at 11:49 PM. Reason: Added code tags

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Socket Client code - not working yet!

    nothing is happening
    Add some print statements to show where the code is executing. If it is blocking somewhere, the print outs will help you find where.
    How and where is the run method called? I don't see any statements in the posted code that will call the run method.

    Is the run method supposed to be named main?

    When adding code be sure to wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    Last edited by Norm; 07-18-2019 at 01:33 AM.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Socket Client code - not working yet!

    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    Bob M is offline Member
    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0

    Default Re: Socket Client code - not working yet!

    Please disregard this conversation as I have updated my code

Similar Threads

  1. multithreaded client socket
    By mdpkishore in forum Advanced Java
    Replies: 4
    Last Post: 08-26-2012, 01:31 PM
  2. POP3 Client Socket Problem
    By danielinthebed in forum New To Java
    Replies: 1
    Last Post: 02-15-2012, 03:09 PM
  3. Identify Client in Socket Client Server Application
    By masadjie in forum Networking
    Replies: 1
    Last Post: 12-20-2007, 09:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •