Re: SimpleReach
Re: SimpleReach
- Subject: Re: SimpleReach
- From: Quinn <email@hidden>
- Date: Wed, 3 Nov 2004 12:53:06 +0100
At 13:00 +0100 3/11/04, Marc Manthey wrote:
marxg4:~ marxg4$ /Users/marxg4/Desktop/SimpleReach/build/SimpleReach
./Simplereach 195.14.205.23
t = kSCNetworkFlagsTransientConnection
r = kSCNetworkFlagsReachable
c = kSCNetworkFlagsConnectionRequired
C = kSCNetworkFlagsConnectionAutomatic
i = kSCNetworkFlagsInterventionRequired
l = kSCNetworkFlagsIsLocalAddress
d = kSCNetworkFlagsIsDirect
Hit ^C to exit.
12:38:40 ------- ./Simplereach (from main)
12:38:40 ------- 195.14.205.23 (from main)
12:38:40 ------- ./Simplereach
12:38:40 tr---l- 195.14.205.23 <----------- and this means it
gets this data from my machine right?
^C
marxg4:~ marxg4$
trl:
t = kSCNetworkFlagsTransientConnection
r = kSCNetworkFlagsReachable
l = kSCNetworkFlagsIsLocalAddress
I'm still a little confused, but I'll take a stab at it. I presume
that 195.14.205.23 is one of the IP addresses on your machine. If
so, this is what the SimpleReach is telling you by returning the
kSCNetworkFlagsIsLocalAddress flag.
A more interesting test is to target a remote machine, such as www.apple.com.
$ ./SimpleReach www.apple.com
t = kSCNetworkFlagsTransientConnection
r = kSCNetworkFlagsReachable
c = kSCNetworkFlagsConnectionRequired
C = kSCNetworkFlagsConnectionAutomatic
i = kSCNetworkFlagsInterventionRequired
l = kSCNetworkFlagsIsLocalAddress
d = kSCNetworkFlagsIsDirect
Hit ^C to exit.
12:11:03 ------- www.apple.com (from main)
12:11:04 -r----- www.apple.com
^C
This result is pretty dull because I'm on a LAN, but if was on dialup
I'd also see kSCNetworkFlagsTransientConnection.
* * *
The SCNetworkReachability and SCNetworkConnection are designed to
work in concert to allow you to develop applications that are network
aware, that is, work well in dialup and mobile environments. The
basic idea is as follows.
o Imagine a program like Mail. When the user goes to check their
mail, it needs to open a TCP connection to mail.example.com. To
start with, it checks whether that address is reachable.
- If the address is reachable, the program can connect immediately
to the server.
- If the address is not reachable, it can display an error directly.
- If the address is reachable but by a transient link that's down,
it can use SCNetworkConnection to bring the link up. Typically it
would only do that after asking the user.
o While the TCP connection is open, the program can continue to
monitor the reachability of the remote machine. If it goes
unreachable, the program can take appropriate action.
- My preferred approach is to inform the user (by displaying an
appropriate message in the progress dialog) and then let the
user cancel the operation, if they feel like it. This makes
the connection resilient to transient network failures (the
classic "whoops, my foot got trapped in the Ethernet cable
and yanked it out of the computer" problem).
- Another common approach is to start a timer. If the remote machine
does not become reachable before the timer expires, it cancels
the operation.
I'm working with folks in Apple Developer Relations to publish an
article that explains all this in more depth. As part of that I've
created a state diagram that shows how an application might work.
I've included the states at the end of this email. If you take this
text, copy it into a file call "SCF.dot", and then open "SCF.dot" in
Graphviz, you'll see what I mean.
[Graphviz is a very cool toy. It's free to download from:
<http://www.pixelglow.com/graphviz/>
]
S+E
--
Quinn "The Eskimo!" <http://www.apple.com/developer/>
Apple Developer Technical Support * Networking, Communications, Hardware
--------------------------------------------------------------------------
digraph states {
size="3,2";
node [shape=ellipse];
idle -> startReach [label = "[Check]"];
error -> idle [label = "[OK]"];
startReach -> waitReach [label = "ok"];
startReach -> error [label = "err", weight = -1];
waitReach -> startPPPConnect [label = "transient"];
waitReach -> startTCPConnect [label = "yes"];
waitReach -> error [label = "no/err"];
startPPPConnect -> waitPPPConnect [label = "ok"];
startPPPConnect -> error [label = "err", weight = -1];
{
rank = same;
waitTCPConnect;
startTCPDisconnect;
}
waitPPPConnect -> startTCPConnect [label = "ok"];
waitPPPConnect -> error [label = "err", weight = -1];
startTCPConnect -> waitTCPConnect [label = "ok"];
startTCPConnect -> error [label = "err", weight = -1];
waitTCPConnect -> error [label = "err", weight = -1];
waitTCPConnect -> transfer [label = "ok", weight = 5];
startTCPDisconnect -> idle [label = "ok"];
startTCPDisconnect -> error [label = "err", weight = -1];
transfer -> writeData [label = "data"];
transfer -> startTCPDisconnect [label = "EOD", weight = 5];
transfer -> error [label = "err", weight = -1];
transfer -> startTimer [label = "unreachable"];
startTimer -> transfer [label = "ok"];
startTimer -> error [label = "err", weight = -1];
transfer -> cancelTimer [label = "reachable"];
cancelTimer -> transfer [label = "ok"];
cancelTimer -> error [label = "err", weight = -1];
writeData -> transfer [label = "ok"];
writeData -> error [label = "err", weight = -1];
transfer -> error [label = "timer"];
}
--------------------------------------------------------------------------
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden