We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Sockets

tricks801
tricks801 asked
on
Medium Priority
344 Views
Last Modified: 2008-02-01
why does socket.getLocalAddress() put a slash in front of the adress
ex. /192.168.1.100
Comment
Watch Question

Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Top Expert 2006

Commented:
because there is no defined protocol.
Top Expert 2006

Commented:
with a defined protcol such as ftp or http, you would get
ftp:/192.168.1.100 or http:/192.168.1.100
so without the protocol, you still keep the "/".
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
> because there is no defined protocol.

An IP address doesn't have a protocol does it?
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
The slash is actual used to seperate hostname and address. But in your case the name is unknown so it is blank.
Top Expert 2006

Commented:
note that when you define a protocol and a port,
you use something like this http:/192.168.1.100:80
you can see that the separator is ":"
so, again, if you dont specify neither the protocol nor the port, you just get "/192.168.1.100"
Top Expert 2006

Commented:
> An IP address doesn't have a protocol does it?
i agree, but we're not talking about an ip address here, we're talking about an instance of SocketAddress...  and its toString() method as you mentioned before
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
> note that when you define a protocol and a port,

An IP address does not have a protocol or a port.

> you use something like this http:/192.168.1.100:80

That is not an IP address, 192.168.1.100 is the IP address

Top Expert 2006

Commented:
i was just explaining why the toString method leaves the slash.
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
> but we're not talking about an ip address here

I think we actually are

> we're talking about an instance of SocketAddress

Even if we were the same applies.
Top Expert 2006

Commented:
oops, it's not an instance of SocketAddress but an instance of java.net.InetAddress.
SocketAddress is for ServeSocket.
javadoc says about InetAddress:
"This class represents an Internet Protocol (IP) address."
which talks about "Protocol" as well as "(IP) address".
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
Yes the *Internet* Protocol :) Thats what IP stands for.
Top Expert 2006

Commented:
> The slash is actual used to seperate hostname and address. But in your case the name is unknown so it is blank.
ok, that's fine with me.
Top Expert 2006

Commented:
i was reading the wrong javadoc page.  :-)
There are several layers of protocols. The Internet Protocol (as in IP) sits on the lower levels of the protocol stack and handles routing of packets. The TCP part of TCP/IP handles packet ordering, and connections for connection based communication.

An IPv4 address is x.y.z.w, where each x,y,z and w can hold values same as an unsigned byte. A port, however is local "routing" information, dependent on a protocol sitting on top of TCP/IP. You need both to make a connection to another computer over TCP/IP.

http, which is another protocol, but an application layer protocol, sits on top of TCP/IP, but is separate from TCP/IP.
Top Expert 2006

Commented:
> http, which is another protocol, but an application layer protocol, sits on top of TCP/IP, but is separate from TCP/IP.
i agree, http has nothing to do with this question.
sorry for all this mess i created.
No worries mate  ;-)
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
> sorry for all this mess i created.

sok :)
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.