Avatar of tricks801
tricks801 asked on

Sockets

why does socket.getLocalAddress() put a slash in front of the adress
ex. /192.168.1.100
Java

Avatar of undefined
Last Comment
Mick Barry

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Mick Barry

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
GrandSchtroumpf

because there is no defined protocol.
GrandSchtroumpf

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 Barry

> because there is no defined protocol.

An IP address doesn't have a protocol does it?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Mick Barry

The slash is actual used to seperate hostname and address. But in your case the name is unknown so it is blank.
GrandSchtroumpf

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"
GrandSchtroumpf

> 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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Mick Barry

> 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

GrandSchtroumpf

i was just explaining why the toString method leaves the slash.
Mick Barry

> 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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
GrandSchtroumpf

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 Barry

Yes the *Internet* Protocol :) Thats what IP stands for.
GrandSchtroumpf

> 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.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
GrandSchtroumpf

i was reading the wrong javadoc page.  :-)
Tommy Braas

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.
GrandSchtroumpf

> 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.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Tommy Braas

No worries mate  ;-)
Mick Barry

> sorry for all this mess i created.

sok :)
Mick Barry

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.