Results 1 to 5 of 5

Thread: Networking Help

  1. #1
    rp181 is offline Member
    Join Date
    Mar 2009
    Posts
    70
    Rep Power
    0

    Default Networking Help

    Hello,
    I am working on a java apllication as part of a batch rendering system for over the network. I am trying to get the client to connect to the server, but it keeps failing.

    The server network code:
    ServerSocket serverSocket = null;
    try {
    serverSocket = new ServerSocket(18018);
    output.append("Creating Socket Success\n");
    } catch (IOException e) {
    output.append("Error. Could not listen.\n");
    }

    output.append("Creating Client Socket on port 18018...\n");
    Socket clientSocket = null;
    try {
    clientSocket = serverSocket.accept();
    output.append("Accept Success: 18018\n");
    } catch (IOException e) {
    output.append("Accept failed: 18018\n");
    }
    String filesss = "";
    for(int d = 1; d <= fpc; d++){
    filesss = filesss.concat(files[(d+1)*1].toString()+"\n");
    }
    //output.append("Sending Commands: \n"+filesss+"\n");

    PrintWriter out = new PrintWriter(
    clientSocket.getOutputStream(), true);



    out.println(filesss);
    out.close();

    clientSocket.close();
    serverSocket.close();

    ================================================== ===
    and client code:
    ================================================== ===


    package luxbatchrender_client;
    import java.net.*;
    import java.io.*;
    public class luxbatchrender_client {
    public static void main(String[] args) throws IOException{
    Socket kkSocket = null;
    PrintWriter out = null;
    BufferedReader in = null;

    try {
    kkSocket = new Socket("192.168.2.8", 18018);
    out = new PrintWriter(kkSocket.getOutputStream(), true);
    in = new BufferedReader(new InputStreamReader(kkSocket.getInputStream()));
    } catch (UnknownHostException e) {
    System.err.println("Don't know about host: 192.168.2.8");
    System.exit(1);
    } catch (IOException e) {
    System.err.println("Couldn't get I/O for the connection to: 192.168.2.8");
    System.exit(1);
    }


    String fromServer;
    fromServer = in.readLine();
    System.out.println(fromServer);
    out.close();
    in.close();
    kkSocket.close();


    }
    }



    ============================================

    I keep getting an exception in the server program at this line:
    PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);

    why is this?

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    10

    Default

    Are we supposed to guess the exception that you got?
    Why can't you tell us?

  3. #3
    rp181 is offline Member
    Join Date
    Mar 2009
    Posts
    70
    Rep Power
    0

    Default

    Im not sure what exception it is. I encased the whole thing in a try wrapper, and in the catch statement, e.getMessage() returns null.

  4. #4
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    8

    Default

    Java Code:
    catch(Exception e)
    {
       e.printStackTrace();
    }
    My Hobby Project: LegacyClone

  5. #5
    rp181 is offline Member
    Join Date
    Mar 2009
    Posts
    70
    Rep Power
    0

    Default

    Thanks for the suggestions, but i fixed it. It turns out the error was completley unrelated to networking, i just put a wrong algorithim to concat a string, and that was returning a null value. For some reasons, netbeans marked the wrong line.

    Sorry. :)

Similar Threads

  1. Networking in Java
    By thangavel14 in forum Networking
    Replies: 3
    Last Post: 07-30-2009, 01:47 AM
  2. Java networking.
    By tim in forum New To Java
    Replies: 7
    Last Post: 07-16-2009, 10:43 PM
  3. Qualifications in Networking
    By javaNoob2 in forum Networking
    Replies: 1
    Last Post: 03-16-2009, 07:47 AM
  4. Networking Problem
    By Ambuscade in forum Networking
    Replies: 21
    Last Post: 11-05-2008, 04:12 AM
  5. help with networking and threads
    By byuu in forum Networking
    Replies: 9
    Last Post: 05-21-2008, 05:03 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
  •