Getting client address from server

Hello friends! I want to get the client's address from the server. How to get it?
[96 byte] By [namara] at [2007-10-3 5:20:27]
# 1

> Hello friends!

> I want to get the client's address from the

> server. How to get it?

It depends what kind of server this is and what sort API you have for communication with it.

Generally speaking what you want is the remote address of the Socket. However you may not have direct access to the socket.

So please what kind of server is this (something you wrote yourself, Tomcat, something else)?

cotton.ma at 2007-7-14 23:27:21 > top of Java-index,Java Essentials,Java Programming...
# 2
Thanks for u r reply cotton.....I am connected to a network connection(Windows 2000 server or something else). I m running a java program in that server PC. Using that program i want to get all the client's address connected to that network.
namara at 2007-7-14 23:27:22 > top of Java-index,Java Essentials,Java Programming...
# 3

> Thanks for u r reply cotton.....

>

> I am connected to a network

> connection(Windows 2000 server or something else). I

> m running a java program in that server PC. Using

> that program i want to get all the client's address

> connected to that network.

From this I conclude that you do have access to the socket instance in question. So use the getInetAddress method of socket.

See this [url=http://java.sun.com/j2se/1.5.0/docs/api/java/net/Socket.html#getInetAddress()]http://java.sun.com/j2se/1.5.0/docs/api/java/net/Socket.html#getInetAddress()[/url]

cotton.ma at 2007-7-14 23:27:22 > top of Java-index,Java Essentials,Java Programming...
# 4

When the client makes a connection through a socket, then the Socket and ServerSocket classes give you the means to access the remote address. See those APIs, and this tutorial:

http://java.sun.com/docs/books/tutorial/networking/sockets/index.html

Now, you still haven't said what kind of server, or what kind of API you're using, so you might not have access to the sockets, and the API may expose the client's address differently, or not at all.

Finally, if the client is behind a proxy, then the address you'll get will not be for the client's PC, but for the proxy, and that same proxy could be fronting for dozens or hudreds of clients.

jverda at 2007-7-14 23:27:22 > top of Java-index,Java Essentials,Java Programming...
# 5
Let me tell what i m doing actually..........I need to copy a file to all the nodes in the network(LAN). For that i hv to run a java program in only one machine(mostly server of the n/w) that shouldcopy that file to all the nodes on the network..........How to do
namara at 2007-7-14 23:27:22 > top of Java-index,Java Essentials,Java Programming...
# 6

> Let me tell what i m doing actually..........

> I need to copy a file to all the

> nodes in the network(LAN). For that i hv to run a

> java program in only one machine(mostly server of the

> n/w) that should

> copy that file to all the nodes on the

> network..........

>How to do this?

1) You would need to detect all the nodes. Or have them register themselves with your server or something

2) You need to send the files. I guess your own client/server would work for this.

It's still a bit hard to tell what you intend and what you mean by "copy file". If you don't want to send the files directly you could use SAMBA or something.

cotton.ma at 2007-7-14 23:27:22 > top of Java-index,Java Essentials,Java Programming...
# 7

> Let me tell what i m doing actually..........

> I need to copy a file to all the

> nodes in the network(LAN). For that i hv to run a

> java program in only one machine(mostly server of the

> n/w)

Then that machine is not a server in the context of your Java app.

> that should

> copy that file to all the nodes on the

> network..........

>How to do this?

There has to be some sort of server or server-ish process running on all those nodes, or a client on those nodes that knows to go out to the "main" box and fetch the files. Some options:

* Create your own Java program that acts as a server on those boxes to take file push requests from the main box.

* Create your own Java program that acts as a client on those boxes to go out and pull files from the main box.

* Start up ftp servers on those boxes (should come with the OS or be downloadable) and use an ftp client (library can be obtaine from apache.org I think) in your Java program on the main box to push the files.

* Have those nodes share a disk or portion of a disk, mount those nodes' shared drives on the main box, and use regular file I/O to copy the files.

Bottom line: You cannot do this purley from the "server" side. There has to be some setup on the "clients" to enable them to accept the file.

jverda at 2007-7-14 23:27:22 > top of Java-index,Java Essentials,Java Programming...
# 8
Hello cotton,Can u tell me what is SAMBA...or send me the link abt SAMBA....Thanks in advance for u r kind help.
namara at 2007-7-14 23:27:22 > top of Java-index,Java Essentials,Java Programming...
# 9
http://en.wikipedia.org/wiki/Server_Message_Block http://jcifs.samba.org/I really think you do need to review the Networking tutorial (link posted by jverd) it is not at all clear that you know enough about what you are trying to do...
cotton.ma at 2007-7-14 23:27:22 > top of Java-index,Java Essentials,Java Programming...
# 10
Ah-choo!Sorry, I think I may have caught some kind of virus around here.
warnerjaa at 2007-7-14 23:27:22 > top of Java-index,Java Essentials,Java Programming...