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

    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]));
    Thanks,

  2. #2
    Join Date
    Aug 2009
    Posts
    49
    Rep Power
    0

    Default

    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.

    cordially
    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
    Posts
    2,388
    Rep Power
    7

    Default

    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, 11:32 AM
  2. append response to the request from Socket and write to another socket
    By vaibhav_singh_vs@yahoo.co in forum Networking
    Replies: 3
    Last Post: 04-17-2009, 07:02 PM
  3. help about Socket
    By fahien_akim in forum New To Java
    Replies: 0
    Last Post: 04-16-2009, 10: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, 02:20 PM
  5. XML through a socket
    By Heather in forum XML
    Replies: 2
    Last Post: 07-04-2007, 09: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
  •