Hi,

Dear Friends i am working on my Project of Chatting...

i want to chat with the Client having the specific ip address, so i just pass the ip address of my friend to the server and server will send my message to that ip address... on which a client i listening...

so please tell me

What did the Object of Socket class contain?

can i give the specific ip to connect to the socket, which is registered or connected with the server???

Recommended Answers

All 3 Replies

you can use something like this

int port = 8000;
String ipAdd = "192.168.100.5";
int timeout = 1000;

SocketAddress sockAddr = new InetSocketAddress(ipAdd, port);
Socket s = new Socket();
s.connect(sockAddr, timeout);

Dear dickersonka,

THANX for the Reply... :)

BUT Dear Friend,

I want to compare the given ip with the ip bind with the perticular socket..

e.g

if (clientsocket.equals("192.168.1.5");

but it doesn't work, :scared:
plz tell me how can i get the clientsocket ip address so i can compare it with the string of ip address.

I'll help out, but you just need to tell us what you want, if you want to compare ips then say that, not about how to create a socket

you are trying to compare objects with clientsocket.equals

you can use

clientsocket.getInetAddress().getHostAddress().equals("192.168.1.5")
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.