Results 1 to 2 of 2
- 10-09-2009, 09:44 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 8
- Rep Power
- 0
- 10-11-2009, 02:25 AM #2
Member
- Join Date
- Feb 2008
- Location
- Oregon, USA
- Posts
- 49
- Rep Power
- 0
By computer number, I assume you mean IP address.
When you receive a connection from a client using a java.net.Socket object, you can use the getInetAddress() method in Socket to get an InetAddress object and then the getAddress() method in InetAddress to get an array of bytes.
Example:
This code snippet should give you a basic idea of how to get the IP address of a host once it has connected. I did leave out how to broadcast the message, though. If you posted some code then I might be able to help you a little more.Java Code:import java.net.*; ServerSocket serverSocket; Socket client; byte[] address; ... try { serverSocket = new ServerSocket(4444); // open a port for listening client = serverSocket.accept(); // listen on the specified port address = client.getInetAddress().getAddress(); } catch (IOException ioe) { System.out.println("Handle IOException here."); }
Similar Threads
-
Finding the largest number in an array
By starchildren3317 in forum New To JavaReplies: 14Last Post: 11-03-2010, 06:49 AM -
I am new, can anyone help me in Computer Vision?
By howardL in forum IntroductionsReplies: 0Last Post: 04-23-2009, 09:37 AM -
finding length on a number
By thekrazykid in forum New To JavaReplies: 8Last Post: 12-12-2008, 08:07 PM -
Finding the highest number
By jigglywiggly in forum New To JavaReplies: 7Last Post: 11-04-2008, 08:14 AM -
How to check the number of applications connected to MySQL DB
By sandeepspatil in forum JDBCReplies: 2Last Post: 08-08-2007, 10:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks