0

Quick question regarding this

Socket(String host, int port)

If I use these arguments in a client, how would a specify the server have a name and thus reference it in the client?

EDIT

Please excuse me if it's vague. I'm writing and instant messenger in java and using this constructor for the client side socket, it wants to receive the host's name as a string and the host's port as a int. What I'm asking is how do I set/find the host's name in this case?

For example, is the String simply "127.0.0.1" if I'm running it locally? Or is it a specified name like "JavaServer" that I set somewhere somehow?

4
  • 2
    Your question is unclear. please rephrase / elaborate. Commented Mar 11, 2012 at 19:06
  • edited, pardon it being vague! Commented Mar 11, 2012 at 19:09
  • "how do I set/find the host's name in this case?" if you are able to create the required Socket object, it means you have already provided host and port parameters. so use them. isn't it so trivial? Commented Mar 11, 2012 at 19:12
  • 1
    you'd need to know the server name (or its IP address) beforehand. You either configure it in a properties file or get it dynamically by invoking a webservice or some such. Commented Mar 11, 2012 at 19:13

1 Answer 1

2

Well, you could read the documentation for that constructor :-)

It's either a host name (e.g. "chatserver.domain.com") or and IP address as a String (e.g. "192.168.1.10")

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.