I\'m studying java.net
and trying to make a simple app. here is the code:
EDIT: My fault, sorry, but the main problem still exists. Here is
what is the possible reason of this?
The reason for the ArrayIndexOutOfBoundsException
is that you have not passed any arguments to your program. Hence, args[0]
does not refer to a valid array index (btw: I would create a separate local variable instead of assigning to the args[]
array. Technically it is possible, but I would not consider this "good style").
When you pass a parameter to your program, you will get a NullPointerException
since you have not configured your Socket. You need, at least, connect it to some server, e.g. like this:
s.connect(new InetSocketAddress("myserver.example.com", 1234));
Then, when there is an appropriate server running at port 1234 at "myserver.example.com", you will be able to send and receive some data.
For more information about network programming in Java, you should go through the Sockets tutorial.