exception handling

i have a datagram client which checks how many servers are alive on the network now i get these two excpetions "help "

datagramsocket is the name of main() class

>at java.net.PlainDatagramSocketImpl.receive(PlainDatagramSocketImpl.java:136)

>at java.net.DatagramSocket.receive(DatagramSocket.java:712)

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.io.*;

import java.net.*;

import java.lang.String;

class datagramclient

{

publicstaticvoid main(String args[])throws IOException

{

int i;

multidatagram multi=new multidatagram();

}

publicstaticclass multidatagram

{

public multidatagram()throws IOException

{

String[]servers=new String[5];

int i;

DatagramSocket socket=new DatagramSocket();

socket.setSoTimeout(4300);

try

{

byte[]buf=newbyte[256];

InetAddress group =InetAddress.getByName("230.0.0.1");

DatagramPacket packet=new DatagramPacket(buf,buf.length,group,4601);

socket.send(packet);

for(i=0;i<=5;i++)

{

packet =new DatagramPacket(buf,buf.length);

socket.receive(packet);

String add=new String(packet.getData(),0,packet.getLength());

System.out.println(add);

//servers[i]=add;

//System.out.println(servers[i]);

}

}catch(IOException e)

{

System.out.println("couldnt connect initially");

}

}

public multidatagram servers[];

}

}

also i have servers thet run on all computers and reply to the client

[3152 byte] By [noobs_will_rulea] at [2007-11-27 8:42:13]
# 1
That's not two exceptions, that's two lines from an exception stack trace. Please show the entire stack trace. Please also fix that catch block to display the entire exception including its stack trace.4.3 seconds is an odd choice for a timeout. Where did that come from?
ejpa at 2007-7-12 20:41:30 > top of Java-index,Core,Core APIs...
# 2

hi trhanks ejb

i was able to fix the error

now can any body tell me about one more problem

i want the host name of the server to which my client connects ,retrieving it fro the packet

i use

>Inetaddress i=INetAddress.getbyName("ip");

>string s=i getHostName();

but both s and i contain the ip,how can i get the host name of this ip

also if there is some message in my packet its not displayed rather i get it in form of blocks (i guess its binary format)

i use thepacket.getData() function

plzzhelp me to clear these two doubts

noobs_will_rulea at 2007-7-12 20:41:30 > top of Java-index,Core,Core APIs...
# 3
InetAddress has methods for that.If you fix a problem you've asked about here, it is common courtesy to share the solution with the forum.
ejpa at 2007-7-12 20:41:30 > top of Java-index,Core,Core APIs...
# 4

hi ejp

actually i just removed the for loop and instead put a

>while(true) condition

so now there pops up no exception

though i now also dont no why it happened

moreover i searched many resources to get hostname but got only the methods mentioned above which i have used but can get ip from those and no host name(because i want to display all hosts alive)

if anyone has any clue

noobs_will_rulea at 2007-7-12 20:41:30 > top of Java-index,Core,Core APIs...
# 5
You don't have to 'search many resources': you only have to look up the API for java.net.InetAddress. It's right there.
ejpa at 2007-7-12 20:41:30 > top of Java-index,Core,Core APIs...
# 6

thanks ejp

but dude i have a new problem now

i have the server which runs on every comp

other is client which when runs checks for servers(sending datagrampackets) and those who send back it retrieves the hostname from the packet

i have checked the route here of packets,the network is straight in the organization(no routers or gateway)

take there are 2 comp A and B

A shows name(A) and name(B)

B shows ip(A) and ip(b)

so this is the problem now

plzz if anybody can give a idea about what this isall about

noobs_will_rulea at 2007-7-12 20:41:30 > top of Java-index,Core,Core APIs...
# 7
Don't call me 'dude' thanks.Apparently B doesn't know the hostname of A. This is a DNS or /etc/hosts issue, not a Java issue.
ejpa at 2007-7-12 20:41:30 > top of Java-index,Core,Core APIs...
# 8

hi ejp first of all my apology

the problem is when i run this prog on more computers

take A,B,C

then

a shows ip of A, Band name of c

B shows ip of Aand rest name of the computers

C shows name of A and ip of B and name of C

so its like that,there seems to be no relation about which computers's name is been resolved by other computer

now plzzz if u can suggest anything

i would be really thankful because this is the last bug left in my small messenger

cheers and sorry again

noobs_will_rulea at 2007-7-12 20:41:30 > top of Java-index,Core,Core APIs...
# 9

> a shows ip of A, Band name of c

So A knows the names of A, B, and C.

> B shows ip of Aand rest name of the computers

So B doesn't know the hostname of A as I said before.

> C shows name of A and ip of B and name of C

So C doesn't know the hostname of B.

> so its like that,there seems to be no relation about

> which computers's name is been resolved by other computer

On the contrary, it is perfectly clear. This is a DNS or /etc/hosts issue, not a Java issue, as I said before.

> now plzzz if u can suggest anything

Fix the DNS or the hosts files on B and C.

> i would be really thankful because this is the last

> bug left in my small messenger

It is not a bug in your small messenger. It is a misconfiguration of the DNS system as seen by B and C, and/or a misconfiguration of their hosts file. There is nothing you can do about that inside Java.

ejpa at 2007-7-12 20:41:30 > top of Java-index,Core,Core APIs...
# 10
thanks again
noobs_will_rulea at 2007-7-12 20:41:30 > top of Java-index,Core,Core APIs...