Dealing with Urls in books
Tonight I spent some time reviewing the latest batch of sample code for Volume 2 of the SLAR. As you may recall, Volume 2 covers System.Xml, System.Net, System.Reflection namespaces (among others). I really want every type and nearly every member in the book to have a real, compliable and run-able code sample that shows common usage.
This poses a little bit of a problem for the System.Net samples. Many of them need to refer to a working webserver and some of them require special behavior from that server. I could just point these all at https://localhost, but I fear that would mean many of them would not run correctly on most customer’s machines unless they do some configuration.
Thoughts on how to handle this?
BTW – if you are interested in being a reviewer for Vol2, please let me know…
Here are a couple of examples:
public class EndPointSample
{
public static void Main()
{
IPAddress ip = IPAddress.Parse("127.0.0.1");
IPEndPoint ep = new IPEndPoint(ip, 9999);
Console.WriteLine("EndPoint.AddressFamily = '{0}'",
ep.AddressFamily.ToString());
SocketAddress sktaddr = new
SocketAddress(AddressFamily.InterNetwork);
EndPoint newep = (EndPoint)ep.Create(sktaddr);
Console.WriteLine("New EndPoint.AddressFamily = '{0}'",
newep.AddressFamily.ToString());
}
}
public class DnsSample
{
private static bool bDone = false;
public static void Main()
{
String toFind = "microsoft.com";
IAsyncResult dummy = Dns.BeginResolve(toFind, new AsyncCallback(DnsCallback), null);
while(!bDone) {}
}
private static void DnsCallback(IAsyncResult ar)
{
IPHostEntry host = Dns.EndResolve(ar);
ShowHostDetails(host);
bDone = true;
}
private static void ShowHostDetails(IPHostEntry host)
{
Console.WriteLine("HostName = '{0}'", host.HostName);
foreach (IPAddress addr in host.AddressList)
{
Console.WriteLine("IPAddress = {0}", addr.ToString());
}
foreach (String alias in host.Aliases)
{
Console.WriteLine("Alias = {0}", alias);
}
}
}
public class HttpStatusCodeSample
{
public static void Main()
{
HttpWebRequest req = (HttpWebRequest)
WebRequest.Create("https://localhost");
HttpWebResponse result = (HttpWebResponse)req.GetResponse();
Console.WriteLine("HttpWebResponse.StatusCode = {0}",
result.StatusCode.ToString());
}
}
Comments
Anonymous
December 05, 2004
The comment has been removedAnonymous
December 05, 2004
Ship a really simple webserver sample and then in your examples connect to that server on localhostAnonymous
December 05, 2004
private static bool bDone = false;
...
while(!bDone) {}
....
bDone = true;
[Off topic] Your example is not good. The while loop does a busy wait and the "read" of bDone could actually be hoisted out of the loop so that it never terminates. Isn't there a simple Event API you can use? While that is not the topic of your article, this is code people will copy.Anonymous
December 05, 2004
Instead of the busy wait, it could create a ManualResetEvent and use WaitOne to block.Anonymous
December 05, 2004
The comment has been removedAnonymous
December 06, 2004
My suggestion is have a separate appendix item that has instructions to configure the webserver that is referenced in the chapters. Then have a disclaimer in the introduction that explains that any code samples are written assuming that the reader has configured their webserver per the instructions in Appendix <insert letter>.
I think that would be the easiest way to handle the issue....Anonymous
December 06, 2004
I agree with the appendix, but one suggestion might be to have a configuration test program to make sure that not only a web server exists but also that the mail server is turned on, FTP and anything else you need. Just a simple winforms app that checks to make sure they all exist and have the right permissions. It shouldn't be nearly as complex as it sounds.Anonymous
December 06, 2004
The trouble is, you probably need more than a web server for demonstrating other protocols etc.. And depending on what you are trying to do, going out to another server may run into firewalls.
So the best thing would be: 1) write a program that tests the user's machine and lets her know what will and won't run, why, and what needs to be done to fix it; 2) maintain a public server for this book, or list suggestions of what server out there provides the needed functionality; 3) include a simple web server for testing (Webmatrix?).
To make all this easier, add a simple program that pops up a dialog to configure all this. Then read the host name you need and whatnot from a configuration file created by this program.
Asking people to install all kinds of services for this book is a no starter. One, it's difficult; two, it opens up all kinds of potential holes; and three, it probably requires expensive software that's only included with Windows Server. So if you do include a web server, or a simple pop server etc., make it a program the user can start for experimenting, but that exits immediately upon logout.Anonymous
December 06, 2004
Point to http://localhost and provide a Windows Installer package on CD or Website that would setup the web server (or machine) as necessary.
I'm interested in being a reviewer for Vol2.Anonymous
December 09, 2004
The comment has been removedAnonymous
December 31, 2004
The comment has been removedAnonymous
May 29, 2009
PingBack from http://paidsurveyshub.info/story.php?title=brad-abrams-dealing-with-urls-in-booksAnonymous
June 15, 2009
PingBack from http://mydebtconsolidator.info/story.php?id=13692Anonymous
June 15, 2009
PingBack from http://debtsolutionsnow.info/story.php?id=2632Anonymous
June 16, 2009
PingBack from http://workfromhomecareer.info/story.php?id=16280Anonymous
June 16, 2009
PingBack from http://fixmycrediteasily.info/story.php?id=4366Anonymous
June 19, 2009
PingBack from http://edebtsettlementprogram.info/story.php?id=23960