Networking
own problems and a lot of overkill.
Does it possible to have two thread running at the same time which reads from the same
socket. If a message is received, does both threads then receive it?
Answer: Two threads can read data from the same socket input stream, but they WON T each
get copies of the same data. They ll each get separate parts of the message.
Q: how can I get an IP Adress in the class InetAdress? The constructor is private, so I can't
use it. I want to call the method getName () to get the domain name out of an IP Adress.
Answer:  It is not necessary to construct something : )
Just do it like this:
for example: String hostname = InetAddress.getLocalHost().getHostName();
 I m converting an old java client/server program which is based on raw byte stream heavily
into new one which requires utilizing object streams. But if I open input/output object streams
on both sides this blocks system and won t proceed...
Hi,
I m converting an old java client/server program which is based on raw byte stream heavily
into new one which requires utilizing object streams. But if I open input/output object streams
on both side this blocks system and won t proceed.
ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
ObjectOutputStream out = new
ObjectOutputStream(socket.getOutputStream());
Answer:  Upon opening the ObjectInputStream, the constructor blocks to read a header from
the stream (doing who knows what). Now, what happens is, both your client and server open
the InputStream... and happily wait forever for the other side to send them the header they
want. Deadlock guaranteed!
The solution is simple: open the ObjectOutputStream first on at least one side, but better on
both sides (usually, symmetry == good). Problem solved
:)
You are trying to keep two streams going at once independently, right.
That means you need at least two threads at each end.
Are there classes available to read and write to an RS 232 port or does this require using
native code?
Answer:  See the Java Communications API.
 Q: Is there a System property that ll tell me the (TCP/IP) machine name? If not, how do
you go about it?
I need to display all the machine s TCP/IP addresses to the user. This requires a call to
InetAddress.getAllByName(), which requires the machine name. You *can t* pass null or
"localhost" to this method. Well, you can pass "localhost", but that only gets you the localhost
addy itself 
127.0.0.1. Not useful.
Answer:  Try this: Working that out, I tried
String hostname = InetAddress.getLocalHost().getHostName();
System.out.println(hostname);
file:///F|/a_jsite/350_tips/networking.htm (2 of 4) [2001 07 08 11:24:57]






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java web hosting

 

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved