Solved

Sockets

Posted on 2004-03-26
19
282 Views
Last Modified: 2008-02-01
why does socket.getLocalAddress() put a slash in front of the adress
ex. /192.168.1.100
0
Comment
Question by:tricks801
  • 9
  • 8
  • 2
19 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 10691523
cause thats the format toString() uses.

If u don't want it try:

getLocalAddress().getHostName();
or
getLocalAddress().getHostAddress();
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10691526
because there is no defined protocol.
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10691536
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 "/".
0
 
LVL 92

Expert Comment

by:objects
ID: 10691547
> because there is no defined protocol.

An IP address doesn't have a protocol does it?
0
 
LVL 92

Expert Comment

by:objects
ID: 10691563
The slash is actual used to seperate hostname and address. But in your case the name is unknown so it is blank.
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10691577
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"
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10691597
> 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
0
 
LVL 92

Expert Comment

by:objects
ID: 10691600
> 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

0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10691608
i was just explaining why the toString method leaves the slash.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 92

Expert Comment

by:objects
ID: 10691615
> 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.
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10691655
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".
0
 
LVL 92

Expert Comment

by:objects
ID: 10691696
Yes the *Internet* Protocol :) Thats what IP stands for.
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10691716
> 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.
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10691727
i was reading the wrong javadoc page.  :-)
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10691750
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.
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10691813
> 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.
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10691879
No worries mate  ;-)
0
 
LVL 92

Expert Comment

by:objects
ID: 10691888
> sorry for all this mess i created.

sok :)
0
 
LVL 92

Expert Comment

by:objects
ID: 10749684
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now