How ?

How to create a thread to log , log things like ip and user name that send message to a server ?
[103 byte] By [EuSuzi] at [2007-9-30 19:30:16]
# 1

Please use a more descriptive subject when asking questions.

There are several ways of doing this, here are two:

* Make a static Log class, set up a thread in the class you want to log and call the Log methods in certain time intervals.

* Make the log class with a thread and a pointer to the class you want to monitir and make logs at time intervals.

-s

shelzib at 2007-7-6 23:44:30 > top of Java-index,Java Essentials,Java Programming...
# 2
Before reinventing the wheel, or should I say, the log, check out [url= http://logging.apache.org/]Log4j[/url] and the [url= http://java.sun.com/j2se/1.5.0/docs/guide/logging/overview.html]J2SE 's logging API[/url].
DrLaszloJamf at 2007-7-6 23:44:30 > top of Java-index,Java Essentials,Java Programming...
# 3
Sorry I will be clear in the nex time.but, how can I your tips, I mean , code in Java?
EuSuzi at 2007-7-6 23:44:30 > top of Java-index,Java Essentials,Java Programming...
# 4
Are you asking how to write code? What have you written in Java to date?
DrLaszloJamf at 2007-7-6 23:44:30 > top of Java-index,Java Essentials,Java Programming...
# 5
> Are you asking how to write code? What have you> written in Java to date?I've eaten a date and several figs. Does that count?
filestream at 2007-7-6 23:44:30 > top of Java-index,Java Essentials,Java Programming...
# 6
Come to think of it, when I was in Java, I feasted on [url= http://en.wikipedia.org/wiki/Salak]salak[/url]. Can't find them here in North America :-(
DrLaszloJamf at 2007-7-6 23:44:30 > top of Java-index,Java Essentials,Java Programming...
# 7
Sorry, I齧 not an expert in Java and I can not find anything in my books
EuSuzi at 2007-7-6 23:44:30 > top of Java-index,Java Essentials,Java Programming...
# 8
Did you check the links in reply 2?
nasch_ at 2007-7-6 23:44:30 > top of Java-index,Java Essentials,Java Programming...
# 9
Java's logging API is pretty easy, but you are vague: what do you have so far, what kind of server do youhave, what protocols are you using, etc... etc... And of course: why do you want to do this?
DrLaszloJamf at 2007-7-6 23:44:30 > top of Java-index,Java Essentials,Java Programming...
# 10
It齭 something that my teacher asked me to do.I create a server and a client (socket issue) a client send information to the server and it will be necessary the server record the data from client like ip , user ............
EuSuzi at 2007-7-6 23:44:30 > top of Java-index,Java Essentials,Java Programming...
# 11
My reply to nasch_ I齧 reading that right now
EuSuzi at 2007-7-6 23:44:30 > top of Java-index,Java Essentials,Java Programming...
# 12

Is your question on how to log, or how to find out the client's IP address and "user name"? If it's

the latter, and I assume you are using java.net.Socket, take a look at it's API. There is a method

that will give you the Inet address of the client. From that you can find their IP address, but the

"user name" is not automatically sent. You'll have to have your client write that down the socket.

DrLaszloJamf at 2007-7-6 23:44:30 > top of Java-index,Java Essentials,Java Programming...
# 13
Have a look at http://java.sun.com/j2se/1.3/docs/api/java/net/Socket.html and http://java.sun.com/j2se/1.3/docs/api/java/net/InetAddress.html. The java.net.Socket and java.net.InetAddress classes have methods that return IP information.
AvaB at 2007-7-6 23:44:30 > top of Java-index,Java Essentials,Java Programming...
# 14
Hello.Thank you everybody. The answers were very usefull to me.I齧 just writing my *.java.Thanks so much
EuSuzi at 2007-7-6 23:44:30 > top of Java-index,Java Essentials,Java Programming...