简体   繁体   English

Java tcp / ip套接字

[英]Java tcp/ip sockets

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. 我在java中编写和即时消息,并使用此构造函数作为客户端套接字,它希望接收主机的名称作为字符串,主机的端口作为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? 例如,如果我在本地运行它,那么字符串是“127.0.0.1”吗? Or is it a specified name like "JavaServer" that I set somewhere somehow? 或者它是一个指定的名称,如“JavaServer”,我设置在某处?

Well, you could read the documentation for that constructor :-) 好吧,你可以阅读该构造函数的文档:-)

It's either a host name (eg "chatserver.domain.com") or and IP address as a String (eg "192.168.1.10") 它是主机名(例如“chatserver.domain.com”)或IP地址作为字符串(例如“192.168.1.10”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM