Testing NAT Breakthrough Code

Someone asked on Stack Overflow:

I am very interested in at least trying to implement NAT break through for my senior project. (I am doing a networking API). It’s not even a requirement of my project, just a interest of mine. I know the basics of how it works, correct me if I’m wrong: Two clients connect to a server that isn’t behind a NAT and this server, knowing the IP of these two clients, tell the clients to connect to each other at the same time. Thus the “Breakthrough”.

This seems not terribly easy or terribly hard to code. However, the part I’m stuck at is the testing of this. Is there a reasonable setup I can do with just one router/one NAT and my three available computers?

Thanks for any advice!

I posted the following answer, which was chosen as the accepted answer and received 1 upvote:

In terms of code/theory on NAT breaking, I cannot offer advice, but I can make some suggestions on setting up a test environment.

You can download a copy of m0n0wall and run it inside of a Virtual PC image (both free). This will give you a second router w/out purchasing any additional hardware. With this extra router, you can create a seperate subnet for your two clients.

Another, easier to grasp option is simply to pickup a second router, you can get a good one pretty cheap.

Then setup your existing router and server as they are now, a 192.168.1.x /24 subnet; then setup your second router (m0n0wall/hardware router) as 192.168.2.x /24 subnet, and plug the second router’s “internet” port into one of the “PC” ports on your first router. Then plug both clients into the second router.

(I realize thats a bit confusing, comment if you cannot follow what I mean)


Originally posted on Stack Overflow — 1 upvotes (accepted answer). Licensed under CC BY-SA.

Best Type to set as return type for methods that return a collection?

I asked this on Stack Overflow:

Which is the best type to us for returning collections?

Should I use IList<T>, IEnumerable<T>, IQueryable<T>, something else? Which is best and why?

I’m trying to decide which I should use typically, both in the interface and the implementation of a few classes that I’m writing.

edit Let me nail this down a little further, I am using LINQ to SQL to return data over a WCF Service. It feels like that may make a change in the best type to use?


Mike Two answered (1 upvotes):

I default to IEnumerable. I’m shooting for the minimal interface to expose. Both IList<T> and IQueryable<T> implement IEnumerable<T>. So unless you have other specific requirements for the methods I’d go for minimalism and use the least derived type. If you have other requirements in your calling code, such as performance of indexed lookups or getting the number of items in the collection then you might want to choose another type such as ICollection<T>.

Notable comments

Nate (0 upvotes): How then would the consumer use it? if the method returns IEnumerable how does the consumer call that method and store the result? What concrete generic types use IEnumerable?

Nate (0 upvotes): Per the comment above, When using ‘IEnumerable’ how does the consumer of my class use it? Just explict cast back to ‘List’?


Originally posted on Stack Overflow — 15 upvotes. Licensed under CC BY-SA.

Watermark on hotlinked images?

Someone asked on Stack Overflow:

I wonder if its possible to have a watermark on hotlinked images on an external site, but not on the original site? I’m using jQuery, can I do something about this?

Thanks heaps!

I posted the following answer, which was chosen as the accepted answer and received 2 upvotes:

This is not possible through a client-side technology. You will need to go server based.

If you have access to a server side technology, such as ASP.NET; you could expose all of your images through an ashx handler. This would let you display a water mark on some images, or not display images at all depending on the source.

Here’s a great article on writing ashx handlers for images — http://dotnetperls.com/ashx-handler/ https://web.archive.org/web/20160311222240/http://www.dotnetperls.com/ashx-handler

If you are using a *nix based server, @Jojo has some links for using php to similar effect.

After writing such a handler in ASP.NET or php, you’ll need to check the HTTP Referer to see if it is a page on your site, or a third party site and then do the necessary image processing to produce your watermakr effect.


Originally posted on Stack Overflow — 2 upvotes (accepted answer). Licensed under CC BY-SA.

Windows Service not appearing in services list after install

Someone asked on Stack Overflow:

I’ve created a windows service in C#, using Visual Studio 2008 I pretty much followed this: http://www.codeproject.com/KB/dotnet/simplewindowsservice.aspx

I created a setup project, as instructed to in the article, and ran it… it installs my service to C:\Program Files\Product etc.... however, it does not then appear in the services list..

What am I missing?

I posted the following answer, which was chosen as the accepted answer and received 118 upvotes:

The most important part of the article you linked, is here

To add a custom action to the setup project

1.In Solution Explorer, right-click the setup project, point to View, then choose Custom Actions. The Custom Actions editor appears.

2.In the Custom Actions editor, right-click the Custom Actions node and choose Add Custom Action. The Select Item in Project dialog box appears.

3.Double-click the application folder in the list box to open it, select primary output from MyNewService (Active), and click OK. The primary output is added to all four nodes of the custom actions � Install, Commit, Rollback, and Uninstall.

4.Build the setup project.

If you skip these steps, your setup project will build and copy your files to the correct directory; however, they will not register your binary as a service without these steps.


I should also note that this works for older versions of Visual Studio that had/have the built-in Setup/Deployment project template. The newer versions of Visual Studio have different setup/deployment projects (some requiring third party software.)

I’d recommend looking into WiX Toolset and check here for WiX Installation of Windows Services.


Originally posted on Stack Overflow — 118 upvotes (accepted answer). Licensed under CC BY-SA.

Visual Studio: testing on different a server than developing on

Someone asked on Stack Overflow:

In dreamweaver, it’s really simple to set up a site so when you test a page that you are developing that it deploys it to a different test server that you are developing on and then browses to that page at that location also.

Question: Can you set up Visual Studio so that when you “run” or “View in Browser” that it automatically pushes the pages out to the test server and then browses to that location as well?

I posted the following answer, which was chosen as the accepted answer and received 1 upvote:

You’ve got two options as far as I can see:

  1. Create a local project and set it up to run from your own local IIS, (this is not exactly what you’re asking, but it should be more of an apples to apples test, as opposed to the built-in visual studio web server).

  2. Use Remote Debugging to attach your Visual Studio instance to a remote server, links here and here

With option two, you’ll still likely need to publish/deploy your solution to the server each time, but you will be able to step through and debug your code running on the remote server.


Originally posted on Stack Overflow — 1 upvotes (accepted answer). Licensed under CC BY-SA.

Visual Studio Missing &quot;Open in blend&quot; option

Someone asked on Stack Overflow:

Am I missing something or does that “Open in blend” option in Visual Studio 2008 not exist anymore?

I am using VS 2008 SP1 + Expression Studio 3.0.

I can do it the other way around, from blend to visual studio, but not visual studio to blend.

Cheers

I posted the following answer, which was chosen as the accepted answer and received 3 upvotes:

For me, the “Open in Expression Blend” is only available in Silverlight projects, for WPF projects the option does not exist.


Originally posted on Stack Overflow — 3 upvotes (accepted answer). Licensed under CC BY-SA.

What are the advantages of the WPF ToolBar?

Someone asked on Stack Overflow:

I’m trying to decide whether I should create a simple StackPanel with Buttons on it, or whether I should use the WPF ToolBar class to contain these buttons (I am creating a simple toolbar).

What are the pros and cons to using WPF’s built-in ToolBar control?

So far, these are the only advantages I have seen:

  • The ToolBars can collapse when necessary; additional items are available from a context drop down.
  • If the ToolBar is contained within a ToolBarTray, multiple ToolBars can be repositioned relative to each other.

Are the any other benefits to the WPF ToolBar? Neither of these apply to my simple toolbar.

I posted the following answer, which was chosen as the accepted answer and received 3 upvotes:

I would say use the Toolbar, because you never know when the next project will come along and need it. You also never know when this project may need it. I don’t think there is any real drawback to using it over a StackPanel and the advantage you didn’t mention is you’ll have more experiance with a built in control for the next project.

On the other hand, I don’t see any harm in doing it with the StackPanel, only that if you need to extend functionallity in the future, you’ll have to do some rework.


Originally posted on Stack Overflow — 3 upvotes (accepted answer). Licensed under CC BY-SA.

xbap custom loader in internet explorer

Someone asked on Stack Overflow:

I have a xbap application, which works fine. But the problem is that I’ve nested the xbap app within an iframe. The site`s background color containing the iframe is black. I want to change the xbap application loader (downloader) background color to fit the site appearance.

Any ideas?

I posted the following answer, which was chosen as the accepted answer:

You may want to look into this:

http://scorbs.com/2006/06/28/xbaps-ondemand-clickonce/


Originally posted on Stack Overflow — 0 upvotes (accepted answer). Licensed under CC BY-SA.

Observable Collection Property Changed on Item in the Collection

I asked this on Stack Overflow:

I have an ObservableCollection<T>. I’ve bound it to a ListBox control and I’ve added SortDescriptions to the Items collection on the ListBox to make the list sort how I want.

I want to resort the list at ANY point when any property changed on a child element.

All my child elements implement INotifyPropertyChanged.


micahtan answered (12 upvotes):

Brute force:

  1. Attach handler to each PropertyChanged event for each child item
  2. Grab the ListCollectionView from your CollectionViewSource
  3. Call Refresh.

EDIT:

The code for 1, 2 would live in your code-behind.

For #1, you’d do something like:

private void Source_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
    switch (e.Action)
    {
        case NotifyCollectionChangedAction.Add:
            foreach( SomeItem item in e.NewItems)
            {
               item.PropertyChanged += new PropertyChangedEventHandler(_SomeItem_PropertyChanged); 
            }
            break;
....
**HANDLE OTHER CASES HERE**
....
      }
}

For #2, in your CollectionChanged handler, you would do something like:

private void _SomeItem_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
    ListCollectionView lcv = (ListCollectionView)(CollectionViewSource.GetDefaultView(theListBox.ItemsSource));
    lcv.Refresh();
}

EDIT2: However, in this case, I would strongly suggest that you also check ListCollectionView.NeedsRefresh and only refresh if that is set. There’s no reason to re-sort if your properties have changed which don’t affect the sort.

Notable comments

Nate (0 upvotes): That is correct. When a property of a child item is changed, I would like the sort to reflect this change.


Originally posted on Stack Overflow — 11 upvotes. Licensed under CC BY-SA.

Are there valid reasons to hold data internally as XML?

Someone asked on Stack Overflow:

In the years that I’ve been at my place of employment, I’ve noticed a distinct trend towards something that I consider an anti-pattern: Maintaining internal data as big strings of XML. I’ve seen this done a number of different ways, though the two worst offenders were quite similar.

The Webservice

The first application, a web service, provides access to a potentially high volume of data within a SQL database. At startup, it pulls more-or-less all of that data out of the database and stores it in memory as XML. (Three times.) The owners of this application call it a cache. I call it slow, because every perf problem that’s been run into while working against this has been directly traceable to this thing. (It being a corporate environment, there should be no surprise that the client gets blamed for the perf failure, not the service.) This application does use the XML DOM.

The Importer

The second application reads an XML file that was generated as the result of an export from a third-party database. The goal is to import this data into a proprietary system (owned by us). The application that does it reads the entire XML file in and maintains at least two, sometimes as many as four, copies of the XML file throughout the entire importing sequence. Note that the data can be manipulated, transformed, and configuration can occur before the import takes place, so the importer owns this data in an XML format for it’s entire lifetime. Unsurprisingly, this importer then explodes when a moderately sized XML file is provided. This application only uses the XML DOM for one of it’s copies, the rest are all raw XML strings.

My understanding of common sense suggests that XML is not a good format for holding data in-memory, but rather data should be translated into XML when it’s being output/transferred and translated into internal data structures when being read in and imported. The thing is, I’m constantly running into production code that completely ignores the scalability issues, and goes through a ton of extra effort to do so. (The sheer volume of string parsing in these applications is frightening.)

Is this a common failure to apply the right tool for the job that others people run into alos? Or is it just bad luck on my part? Or am I missing some blindingly obvious and good situations where it’s Right and OK to store high volumes of data in-memory as XML?

I posted the following answer, which was chosen as the accepted answer and received 4 upvotes:

Any data stored in memory should be in classes. The higher volume of data we are talking about, the more important this becomes. Xml is a hugely bloated format that reduces performance. Xml should be used only for transfering data between applications. IMHO.


Originally posted on Stack Overflow — 4 upvotes (accepted answer). Licensed under CC BY-SA.

signed letter b

Dad. Geek. Gamer. Software developer. Cloud user. Old Car enthusiast.  Blogger.


Top Posts


profile for Nate on Stack Exchange, a network of free, community-driven Q&A sites
a proud member of the blue team of 512KB club
Thoughts, opinions, and ideas shared here are my own. © 2026 Nate Bross.