Results 1 to 7 of 7
  1. #1
    Peanut is offline Member
    Join Date
    May 2013
    Posts
    3
    Rep Power
    0

    Default Java Client, C# Server WebChat Programming

    Hi guys,

    I need some guidance with my project.. The first criteria at the moment requires me (client) to connect to a C# server. I'm using Java language (Eclipse) as I'm more familiar with it than C#. So, here's what I have coded now:


    CLIENT
    ------------------------------------------------------------------------------------
    package WebChat;

    import java.net.*;
    import java.io.*;

    public class Client {

    public static void main(String[] args) {

    Socket MyClient = null;
    DataInputStream input = null;
    DataOutputStream output = null;
    String server = "149.xxx.xx.xxx";
    int port = 31180;

    try {
    MyClient = new Socket(server, port);
    input = new DataInputStream(MyClient.getInputStream());
    output = new DataOutputStream(MyClient.getOutputStream());
    }
    catch (IOException e) {
    System.err.println("Couldn't get I/O for the connection to: "+server);
    }


    try {
    output.close();
    input.close();
    MyClient.close();
    }
    catch (IOException e) {
    System.err.println("IOException: " + e);
    }
    }
    }
    --------------------------------------------------------------------------------------------

    And the errors I've received are:

    Couldn't get I/O for the connection to: 149.xxx.xx.xxx
    Exception in thread "main" java.lang.NullPointerException
    at WebChat.Client.main(Client.java:27)



    I can't connect to the server at all and I don't know if it is because if my codes lack something that is needed to interface with the C# server.. Or it is the incorrect port number.. I tried telnet and ping and it seems like the server is running fine.. Really need guidance in the right direction!

    Thank you...

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,800
    Rep Power
    19

    Default Re: Java Client, C# Server WebChat Programming

    When posting code please wrap it in [code] tags [/code] to retain formatting.

    I would recommend changing your catch blocks so that they call printStackTrace() on the exception.
    That way you'll know exactly what exception was thrown, and from where.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Peanut is offline Member
    Join Date
    May 2013
    Posts
    3
    Rep Power
    0

    Default Re: Java Client, C# Server WebChat Programming

    Oh oops! Sorry, am new to forum!

    Okay, I've tried that already and the errors I have now are:

    Couldn't get I/O for the connection to: 149.171.37.231
    java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Un known Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress( Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at WebChat.Client.main(Client.java:17)
    Exception in thread "main" java.lang.NullPointerException
    at WebChat.Client.main(Client.java:28)



    I'm not too sure what do they mean.. :|

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,800
    Rep Power
    19

    Default Re: Java Client, C# Server WebChat Programming

    Well, the NullPointerException is down to the fact that you continue processing after getting the other exception.
    You really should just exit at that point as there's nothing the code can do.

    The main problem is the connection refused, which implies that the server is refusing connections on that port number.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Peanut is offline Member
    Join Date
    May 2013
    Posts
    3
    Rep Power
    0

    Default Re: Java Client, C# Server WebChat Programming

    Okay.. So, the problem lies with the server instead of my codes? Is there any way I am able to fix that?

    Also, I'm supposed to establish a chat-interface once connected to the server. Could you guide me on how am I able to go about that?
    I'm not too sure if the way I called my input and output are right..

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,800
    Rep Power
    19

    Default Re: Java Client, C# Server WebChat Programming

    I'm rubbish with networks I can actually access, let alone ones filtered through the medium of a forum.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,340
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java Client, C# Server WebChat Programming

    Are you sure the server is accepting connections on that port number? The server seems to be alive (you can ping it) ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 1
    Last Post: 07-21-2012, 10:49 AM
  2. Java Server/C Client
    By FallenBlade in forum Networking
    Replies: 13
    Last Post: 03-10-2011, 11:22 PM
  3. Help with some Client-Server Programming
    By leigh507 in forum New To Java
    Replies: 2
    Last Post: 02-23-2011, 02:09 PM
  4. Replies: 2
    Last Post: 09-24-2010, 11:31 AM
  5. PPPoE client programming in java
    By yeadam in forum Networking
    Replies: 0
    Last Post: 12-03-2007, 12:14 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
  •