you sample code named 'HostName.java' run very well.but it is not a servlet
code.I changed it as follows,Of caurse,it run very well also.
//Import Servlet Libraries
import javax.servlet.*;
import javax.servlet.http.*;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class HostName extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
InetAddress ia;
try {
ia = InetAddress.getLocalHost();
out.print("Local host name is " + ia.getHostName());
out.print("Local host IP address is "+ ia.getHostAddress());
}
catch ( UnknownHostException e ) {
out.print("Unknown Local Host");
}
out.close();
}
----- Original Message -----
From: Lambert, Stephen : CO IR <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, July 20, 2000 5:54 AM
Subject: Socket Programming in Java
> Can someone suggest some online demos and docs on Socket Programming in
> Java?
> Preferable with java examples to test.
> Eventually I need to write a servlet that processes messages between
> machines using sockets!
>
> I do have a Linux/Apache/JServ machine working great for my JDBC servlets.
>
> I attempted a sample code(listed below) to get the name and IP from my
> server.
> But, the error I'm getting is "500 Internal Server Error"
> "The server encountered an internal error or misconfiguration and was
unable
> to complete your request."
> My jserv.log file reveals "java.lang.IllegalAccessException: HostName"
> I'm not quite sure how to run this code yet...but hope to get up to speed
on
> this topic of socket programming!
>
> Thanks,
> Stephen.
>
>
>
>
>
> /*************************************************/
> /* HostName - get's name of local machine */
> /*************************************************/
>
> import java.net.InetAddress;
> import java.net.UnknownHostException;
>
> class HostName {
> public static void main(String[] args) {
> InetAddress ia;
>
> try {
> ia = InetAddress.getLocalHost();
> System.out.println("Local host name is "
> + ia.getHostName());
> System.out.println("Local host IP address is "
> + ia.getHostAddress());
> }
> catch ( UnknownHostException e ) {
> System.out.println("Unknown Local Host");
> }
> }
> }
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html