Results 1 to 3 of 3
  1. #1
    castiel is offline Member
    Join Date
    Aug 2009
    Rep Power

    Default Creating Socket Issue

    hey, i'm pretty new at this networking stuff in java and i was wondering
    if someone could tell me how to do this.

    My command line arguments for the client in this java program i'm writing contain the server ipAddress which is args[2] and the port number args[3]

    But i'm not sure how to convert the server "IpAdress" args[2] into an InetAddress so i can create the socket.

    This is my failed attempt, might give you a better idea of what i'm trying to do.

    Java Code:
    clientSocket = new Socket((InetAddress)args[2], Integer.parseInt(args[3]));

  2. #2
    Join Date
    Aug 2009
    Rep Power


    Hi Castiel,

    The args[] is not similar to c++. In java the first argument is counted as args[0] and the second argument is counted as args[1]. Try to print this using System.out.println(args[0]) before considering it for ipaddress.

    Anand Ravindran
    for online java tutorial visit :: Java Needs - Java Programmers' Website ::
    for project dreams visit Webarch Technologies

  3. #3
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Rep Power


    Well you can't cast a String to an InetAddress.

    See the specs for details on how to use it.

Similar Threads

  1. issue after creating plug-in
    By james_nevil in forum Eclipse
    Replies: 0
    Last Post: 08-19-2009, 12:32 PM
  2. append response to the request from Socket and write to another socket
    By in forum Networking
    Replies: 3
    Last Post: 04-17-2009, 08:02 PM
  3. help about Socket
    By fahien_akim in forum New To Java
    Replies: 0
    Last Post: 04-16-2009, 11:41 AM
  4. writting extended ascii chars on socket........or Endianness Issue......??
    By sachinj13 in forum Threads and Synchronization
    Replies: 8
    Last Post: 09-23-2008, 03:20 PM
  5. XML through a socket
    By Heather in forum XML
    Replies: 2
    Last Post: 07-04-2007, 10:31 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