<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Catalyst Development &#187; SocketWrench</title>
	<atom:link href="http://blog.catalyst.com/archives/category/socketwrench/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.catalyst.com</link>
	<description>Applications, Components and Libraries For Software Developers</description>
	<lastBuildDate>Fri, 18 Nov 2011 21:34:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>SocketWrench Internet Server</title>
		<link>http://blog.catalyst.com/archives/103</link>
		<comments>http://blog.catalyst.com/archives/103#comments</comments>
		<pubDate>Mon, 28 Jun 2010 22:54:58 +0000</pubDate>
		<dc:creator>Catalyst</dc:creator>
				<category><![CDATA[SocketTools]]></category>
		<category><![CDATA[SocketWrench]]></category>

		<guid isPermaLink="false">http://blog.catalyst.com/?p=103</guid>
		<description><![CDATA[One of the most popular additions to both SocketWrench and SocketTools has been the Internet Server component. It’s available as an extension to the existing Internet API for C/C++ programmers, an ActiveX control and as a .NET component. While SocketWrench has always included server functionality, we felt that creating a server application was more complex [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most popular additions to both SocketWrench and SocketTools has been the Internet Server component. It’s available as an extension to the existing Internet API for C/C++ programmers, an ActiveX control and as a .NET component. While SocketWrench has always included server functionality, we felt that creating a server application was more complex than it should be. With the Internet Server component, we’ve made the development process as simple as possible, removing the need to build the server framework and allowing you to focus on the actual work the server needs to do.<span id="more-103"></span></p>
<p>You can think of the Internet Server control as a server-in-a-box that handles all of the low level details such as accepting incoming connections from clients, keeping track of the active client sessions and processing each of the various network events that can occur for each client. The server is multi-threaded, with each client sessions being isolated in a separate thread and it is completely event driven. When one of the clients interacts with the server, it raises an event that your code handles. Although the events are similar in function to how SocketWrench works with asynchronous sockets, the Internet Server component uses a completely different event mechanism that doesn’t make use of messaging for the event notifications.</p>
<p>Our design goal was to make creating your own custom server as easy as developing a client application. All you need to do is create your event handlers and start the server. Because each of the client sessions are isolated from one another, you can write your event-handling code in a simple, top-down fashion without getting mired in asynchronous callback notifications. You end up with server code that is easier to write, debug and maintain. We’ve also made sure that the various properties and methods in the Internet Server control are as similar to SocketWrench as possible, minimizing your learning curve and allowing you to easily migrate your existing code.</p>
<p>If you’re currently using the SocketWrench control or .NET class for a server application, take a look at the new Internet Server control. It’s included in both SocketWrench 6.0 and SocketTools 6.0, and you can review the online help at <a href="http://go.catalyst.com/help">go.catalyst.com/help</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.catalyst.com/archives/103/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SocketWrench 6.0 Freeware Released</title>
		<link>http://blog.catalyst.com/archives/63</link>
		<comments>http://blog.catalyst.com/archives/63#comments</comments>
		<pubDate>Tue, 06 Oct 2009 23:02:07 +0000</pubDate>
		<dc:creator>Catalyst</dc:creator>
				<category><![CDATA[SocketWrench]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://blog.catalyst.com/?p=63</guid>
		<description><![CDATA[For hobbyist programmers who are interested in learning about Internet programming, we&#8217;ve released a free version of our popular SocketWrench ActiveX control. It has the standard features of our commercial product, but does not include support for secure connections or the Internet Server components. We&#8217;re offering this to developers as a way to both introduce [...]]]></description>
			<content:encoded><![CDATA[<p>For hobbyist programmers who are interested in learning about Internet programming, we&#8217;ve released a <a href="http://go.catalyst.com/freeware">free version</a> of our popular SocketWrench ActiveX control. It has the standard features of our commercial product, but does not include support for secure connections or the Internet Server components. We&#8217;re offering this to developers as a way to both introduce our components, and help those who want to get started with an easy way to build Internet-enabled applications.<span id="more-63"></span></p>
<p>For professional developers who need security, additional functionality and technical support, we have commercial versions of <a href="http://go.catalyst.com/socketwrench">SocketWrench</a>. Secure connections using SSL/TLS can be easily established, usually with just an extra line of code, and for projects where you need to create a server application, the commercial version also includes the Internet Server component which makes it easy to create custom TCP/IP servers.</p>
<p>For those programmers who are primarily working with native code, such as classic Visual Basic, PowerBasic, C++ and other similar languages, our SocketWrench Secure Edition includes both an ActiveX control and a standard dynamic link library (DLL) that provides an interface that&#8217;s similar to the standard Windows API. It can be used with virtually any programming language, and has a great degree of flexibility.</p>
<p>For Visual Basic .NET and C# developers, we&#8217;ve designed SocketWrench .NET to really simplify Internet programming beyond what&#8217;s included as part of the .NET Framework. Microsoft has a lot of interdependency in their classes where you end up creating a number of different class instances and writing a lot of &#8220;glue code&#8221; to tie them together. An example of this would be the TcpClient class which uses the NetworkStream class, and then to convert the data read to a string, you&#8217;d need to use the System.Text.Encoding class and so on. If you need SSL support, then you&#8217;d also need the SslStream class, and write the code to integrate that. All of this functionality is incorporated directly into SocketWrench, which significantly reduces the amount of code that needs to be written. And as every developer knows, the less code you have to write, fewer errors will be in that code. A simple, straight-forward design is one of the cornerstones of reliable software. Give it a try and let us know what you think.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.catalyst.com/archives/63/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SocketTools 5.0 Technical Support</title>
		<link>http://blog.catalyst.com/archives/34</link>
		<comments>http://blog.catalyst.com/archives/34#comments</comments>
		<pubDate>Mon, 01 Jun 2009 18:51:33 +0000</pubDate>
		<dc:creator>Catalyst</dc:creator>
				<category><![CDATA[General Information]]></category>
		<category><![CDATA[SocketTools]]></category>
		<category><![CDATA[SocketWrench]]></category>

		<guid isPermaLink="false">http://blog.catalyst.com/archives/34</guid>
		<description><![CDATA[Technical support for version 5.0 of all SocketTools Editions, all SocketWrench Editions, and the File Transfer and Internet Mail products will officially end on June 30, 2009. It is recommended that those developers who are currently using version 5.0 download the last available build. Links to download the product files can be found in Knowledge [...]]]></description>
			<content:encoded><![CDATA[<p>Technical support for version 5.0 of all SocketTools Editions, all SocketWrench Editions, and the File Transfer and Internet Mail products will officially end on June 30, 2009. It is recommended that those developers who are currently using version 5.0 download the last available build. Links to download the product files can be found in Knowledge Base <a href="http://www.catalyst.com/cgi-bin/knowbase.cgi?action=view&#038;docid=100269" target="_blank">Article 100269</a>. There will be no further updates or hotfixes published for this version of the product.<span id="more-34"></span></p>
<p>If you are currently using version 5.0, you can <a href="http://www.catalyst.com/order/upgrade.html" target="_blank">upgrade to the current version</a> at a discounted price. Version 6.0 is source compatible with version 5.0 and can be installed side-by-side on the same development system. For more information about what&#8217;s new with SocketTools 6.0, please visit our website. If you have any questions, feel free to post in the technical support forum section appropriate for your product.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.catalyst.com/archives/34/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SocketTools 6.0 Released</title>
		<link>http://blog.catalyst.com/archives/29</link>
		<comments>http://blog.catalyst.com/archives/29#comments</comments>
		<pubDate>Tue, 09 Sep 2008 00:22:58 +0000</pubDate>
		<dc:creator>Catalyst</dc:creator>
				<category><![CDATA[Product Updates]]></category>
		<category><![CDATA[SocketTools]]></category>
		<category><![CDATA[SocketWrench]]></category>

		<guid isPermaLink="false">http://blog.catalyst.com/archives/29</guid>
		<description><![CDATA[We are pleased to announce that SocketTools 6.0 has been released. This new version includes several new components, including a new SSH component for secure interactive terminal sessions and remote command execution, integrated support for secure file transfers using SFTP and a new Internet Server component that allows you to build a customized, scalable, multi-threaded [...]]]></description>
			<content:encoded><![CDATA[<p>We are pleased to announce that SocketTools 6.0 has been released. This new version includes several new components, including a new SSH component for secure interactive terminal sessions and remote command execution, integrated support for secure file transfers using SFTP and a new Internet Server component that allows you to build a customized, scalable, multi-threaded server with only a few lines of code. The SocketTools 6.0 components are source compatible with version 4.0 and 5.0 and support side-by-side deployment, simplifying the upgrade process so that you can spend your time improving your software, not rewriting it.<span id="more-29"></span></p>
<p>The SocketTools 6.0 Secure Editions introduce new components that implement the Secure Shell (SSH) protocol, which can be used to establish a secure, encrypted connection with a server. With an interface that is similar to our Telnet components, you can implement an interactive terminal session, or you can specify that you want a command executed remotely and the output returned to your application. SSH does not require complicated certificate management and is widely supported on most servers today. Of course, the SocketTools Secure Editions continue to also support the SSL and TLS security protocols, providing the widest range of options to developers who require security features for their applications.</p>
<p>The SocketTools Secure Editions also support file transfers using the Secure Shell (SSH) protocol, as well as the SSL and TLS protocols. Also commonly referred to as FTP+SSH, the SocketTools file transfer components can be used to connect to an SSH server and upload or download files, obtain directory listings and perform common file management functions. Because support for SFTP is integrated into the existing FTP components, in most cases all you need to do is specify the SSH port number without making any other changes to your code. The same interface is provided for FTP, FTP+SSL and FTP+SSH, making it easy to offer the widest range of options to your users. Another new feature of the File Transfer Protocol components is the ability to verify that the file on the local system is identical to the file on the server using an MD5 hash or CRC-32 checksum, and automatically setting the correct file transfer mode based on the type of file being uploaded or downloaded. Developers can also explicitly verify the contents of a file, and can even register their own custom file types.  </p>
<p>One of the most complex tasks in Internet software development is creating a custom server application that can reliably handle a large number of client connections. SocketTools 6.0 introduces a new Internet Server component to simplify the development of custom servers, providing an easy-to-use framework where the only code you need to write is in response to events that are sent to your application. With a single function call, you can create a scalable, multi-threaded, event-driven server that can be used to accept connections from clients anywhere in the world, or just on your local intranet. All of the networking, thread management, synchronization and messaging are handled internally by the framework, allowing you to focus on writing your own code without worrying about the complex details of the server implementation.</p>
<p>Developers who need to create an e-mail application that download and store messages on the local system, the Mail Message (MIME) components and library have been expanded to provide a new storage interface that simplifies the storage, retrieval and management of message. Simply create a new storage file, and begin adding messages to it. When you need to access a stored message, you can reference it by an index number, or you can use functions to search for a particular message that contains a specific header value. For example, you can search the message store for all messages that have been sent by someone with a particular e-mail address. There&#8217;s even a compatibility mode where you can import message stores from UNIX mail systems, if needed.</p>
<p>SocketTools 6.0 is fully compatible with both Windows Vista and Windows Server 2008, and is designed to take advantage of new features introduced in Microsoft&#8217;s latest operating system. Our developers use Windows Vista and Visual Studio 2008 as their primary development platform, so we don&#8217;t simply test under Vista, we work with the operating system every day and understand how it impacts application development in the real world. Of course, SocketTools is also fully supported under Windows XP SP2 and SP3, Windows Server 2003 and Windows 2000. If your users are upgrading to Windows Server 2008 or Windows Vista, then we recommend that you to upgrade to SocketTools 6.0 to ensure compatibility.</p>
<p>For more information, please review the <a href="http://www.catalyst.com/support/faq/sockettools.html" target="_blank">SocketTools FAQ</a> in the support section of our website. We also encourage you to download a free evaluation copy of the SocketTools 6.0 Edition that interests you. The evaluation license is valid for a single development system for 30 days, it is completely functional and can be safely installed side-by-side with earlier versions of SocketTools.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.catalyst.com/archives/29/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a Better Server</title>
		<link>http://blog.catalyst.com/archives/28</link>
		<comments>http://blog.catalyst.com/archives/28#comments</comments>
		<pubDate>Tue, 12 Aug 2008 18:54:18 +0000</pubDate>
		<dc:creator>Catalyst</dc:creator>
				<category><![CDATA[Internet Protocols]]></category>
		<category><![CDATA[SocketTools]]></category>
		<category><![CDATA[SocketWrench]]></category>

		<guid isPermaLink="false">http://blog.catalyst.com/archives/28</guid>
		<description><![CDATA[SocketTools 6.0 will introduce a new component and API framework that is designed to simplify the process of creating TCP/IP server applications. In the Library Edition, this will be included as extension of the existing SocketWrench API, with additional functions designed to create an instance of the server and manage the client session. In the [...]]]></description>
			<content:encoded><![CDATA[<p>SocketTools 6.0 will introduce a new component and API framework that is designed to simplify the process of creating TCP/IP server applications. In the Library Edition, this will be included as extension of the existing SocketWrench API, with additional functions designed to create an instance of the server and manage the client session. In the .NET Edition and Visual Edition, it will be included as a new component that has an interface that is very similar to the current SocketWrench component.<span id="more-28"></span></p>
<p>Creating a server application is one of the more complex undertakings when it comes to software development, particularly if the server must support more than just a handful of client sessions. As anyone who has used SocketWrench to create a server application, you know that there are a lot of moving parts, with instances of the component created to listen for incoming connections, additional instances created to accept each client session and a lot of &#8220;glue code&#8221; required to manage the server itself and each of those clients.</p>
<p>The goal for the new Internet Server component was to provide the basic framework for a general purpose TCP/IP server. We wanted to simplify things so that the developer could focus on actually writing the code that has the server do something, rather than struggle with the complexity of building a stable, multi-threaded server that scaled well, supporting a large number of active client sessions. To this end, our requirements were:</p>
<p>1. The interface needed to be similar to our existing components, specifically in terms of SocketWrench. We didn&#8217;t want to force developers to re-learn what they already knew, and so it was decided that the server API would be an extension of the existing SocketWrench API. Developers who have are familiar with the current API can continue to use the same functions in combination with the new functions introduced as part of the server framework. For the ActiveX and .NET components, we intentionally made the interface very similar to the SocketWrench component, minimizing any differences as much as possible. There were inevitably some changes that needed to be made, but we&#8217;re confident that developers who are familiar with SocketWrench will find the Internet Server component to be very easy to use (in fact, it&#8217;s even easier to use).</p>
<p>2. The server framework needed to be multi-threaded and support a reasonably large number of active client sessions. Because of the nature of how Windows Sockets works at a low level, having client sessions isolated in their own thread would make things much easier for developers to implement complex server applications, and it would significantly improve performance overall. By their nature, single-threaded servers (where multiple client sessions are all serviced within a single thread) don&#8217;t scale well and can introduce real performance bottlenecks. The trick, however, was how to support multi-threading in a transparent way, so that developers wouldn&#8217;t be forced to write thread management code. We accomplished this by adopting a completely event-driven model where all of the server&#8217;s working code is implemented as event handlers, and each client session is identified by a unique handle.</p>
<p>3. The server should be resilient, providing protection against common types of denial-of-service attacks, such as flooding. Much of this is handled internally (and transparently) by the server framework, however the developer does have specific control over various aspects of how client sessions are managed. For example, the developer can determine the maximum number of client sessions that will be accepted, the maximum number of clients per IP address, the amount of time that client sessions can remain idle and so forth. This ensures that when the server is deployed, it functions in a real-world environment.</p>
<p>4. The server framework should provided high-level management functions that simplify basic tasks. There are functions that can be used to control the server overall, as well as those designed to manage individual client sessions. For example, stopping the server and gracefully disconnecting the active client sessions can be done in a single method call. We&#8217;ve also made it easy to obtain statistical information about the server (such as the number of active clients currently connected to the server), as well as associate private application-defined data with each client session. Client management was designed to be very flexible, while at the same time easy to use. For example, each client session can be given a string moniker, and referenced by that name rather than its numeric handle value.</p>
<p>5. The server should have low overhead, and be usable as both a stand-alone application as well as a Windows service. The server framework has a small footprint, and was designed to use Windows events rather than a message queue for network event notifications. This internal change not only improved overall performance, it eliminated some of the limitations that SocketWrench has when used to create a server application.</p>
<p>We&#8217;re excited about the upcoming release of SocketTools 6.0 and SocketWrench 6.0, both of which will include the new Internet Server component. If you&#8217;ve used SocketWrench to create an Internet-based server application in the past, or you&#8217;re looking at a future project that will require a service, we think that you&#8217;ll find this new component to be a fantastic addition.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.catalyst.com/archives/28/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New SocketWrench Tutorial</title>
		<link>http://blog.catalyst.com/archives/19</link>
		<comments>http://blog.catalyst.com/archives/19#comments</comments>
		<pubDate>Fri, 17 Aug 2007 20:08:53 +0000</pubDate>
		<dc:creator>Catalyst</dc:creator>
				<category><![CDATA[Internet Protocols]]></category>
		<category><![CDATA[SocketWrench]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://blog.catalyst.com/archives/19</guid>
		<description><![CDATA[We&#8217;ve released an updated version of the SocketWrench Tutorial we originally made for the ActiveX control and Visual Basic. This new version uses the SocketWrench .NET component with Visual Studio 2005, and we believe that it is easier to read and understand, focusing on the developer who is new to Internet programming. The tutorial is [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve released an updated version of the <a href="http://go.catalyst.com/?linkid=1001322" target="_blank">SocketWrench Tutorial</a> we originally made for the ActiveX control and Visual Basic. This new version uses the SocketWrench .NET component with Visual Studio 2005, and we believe that it is easier to read and understand, focusing on the developer who is new to Internet programming. The tutorial is divided into two general sections. The first section provides a broad overview of the concepts and terminology behind Internet programming. This includes topics on the network protocols, the domain name system, and the general design structure of a client-server application. We also include information about data encryption and certificate management using the standard SSL/TLS security protocols.<br />
<span id="more-19"></span></p>
<p>The second section of the tutorial walks you through creating your first Internet application, a web client that will download an HTML source page from a server. We decided to use this as the example because we felt it was simple and easy enough to understand without getting wrapped up in the details of building a more complex application. We&#8217;ve also included a companion video tutorial that demonstrates the same basic concepts.</p>
<p>Sometimes we&#8217;re asked why a developer should use SocketWrench rather than the classes or components which are already included with Visual Studio, or just using the Windows Sockets API directly. The tutorial answers that question by demonstrating how simple SocketWrench is to use. It&#8217;s a component that is useful for developers who are not experts in network programming, and yet it is flexible enough that it can be also be used with very complex applications.</p>
<p>The simplicity of SocketWrench is particularly evident when creating secure applications using SSL and TLS. Establishing a secure connection is a seamless process using the security functionality built into the SocketWrench. It automatically manages all of the complicated encryption and certificate validation, and doesn&#8217;t require you to understand any of the lower level implementation details. It also doesn&#8217;t require that you to use another class, like the SslStream class in .NET. As the tutorial demonstrates, switching between secure and standard (non-secure) connections only involves setting a single property to true or false.</p>
<p>Our goal with SocketWrench is to provide a component that makes it as easy as possible to Integrate Internet functionality in your own applications using code that is generally no more complex than opening, reading from and writing to a file. If you&#8217;re not familiar with Internet programming, we hope this tutorial helps minimize that initial learning curve and gets you started building your first Internet application.</p>
<p>Â»Â <a href="http://go.catalyst.com/?linkid=2147205" target="_blank">An Introduction to Internet Programming</a> (PDF)<br />
Â»Â <a href="http://go.catalyst.com/?linkid=2151391" target="_blank">SocketWrench Video Tutorial</a><br />
Â»Â <a href="http://go.catalyst.com/?linkid=2192914" target="_blank">Download SocketWrench .NET for Visual Studio</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.catalyst.com/archives/19/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SocketTools 5.0 and Multithreading</title>
		<link>http://blog.catalyst.com/archives/9</link>
		<comments>http://blog.catalyst.com/archives/9#comments</comments>
		<pubDate>Thu, 01 Feb 2007 02:36:05 +0000</pubDate>
		<dc:creator>Catalyst</dc:creator>
				<category><![CDATA[SocketTools]]></category>
		<category><![CDATA[SocketWrench]]></category>

		<guid isPermaLink="false">http://blog.catalyst.com/archives/9</guid>
		<description><![CDATA[One of the errors that developers occasionally ask about is the â€œHandle not owned by the current threadâ€ error; what it actually means and the situations in which it can occur. This doesnâ€™t tend to be an error message that developers using the SocketTools ActiveX controls encounter, and before the .NET Edition was released, it [...]]]></description>
			<content:encoded><![CDATA[<p>One of the errors that developers occasionally ask about is the â€œHandle not owned by the current threadâ€ error; what it actually means and the situations in which it can occur. This doesnâ€™t tend to be an error message that developers using the SocketTools ActiveX controls encounter, and before the .NET Edition was released, it was almost exclusively an issue related to the Library Edition. The reason this error exists, the justification for the threading model that is used and how things are changing in version 5.0 involves a bit of a history and the origins of SocketTools.<br />
<span id="more-9"></span></p>
<p>The first release of SocketTools consisted of two versions, a 16-bit version for the Windows 3.1 platform, and a 32-bit version for the Windows 95 platform, which was new at the time. Visual Basic 4.0 had been released, and with it came the new OLE controls which were later renamed to ActiveX. Initially, SocketTools was only available as controls (16-bit VBXs and 32-bit OCXs) and their code was largely shared between the two versions. When the decision was made to release a Library Edition that consisted of standard Windows DLLs, we had to go back to the drawing board to some extent.</p>
<p>There were a fair number of assumptions in the core networking code that worked well when it was in a control targeted for a single language. On the other hand, porting that code to standard DLLs presented a problem because a DLL can be used with virtually any Windows programming language. The solution was toÂ redesign that core code from the ground up, focusing on implementing the DLL interfaces first, and then building the ActiveX controls on top of that API. All of the â€œinside knowledgeâ€ that the ActiveX controls depended on had to be removed and redesigned. The decision was made early on that we didnâ€™t want to create undocumented functions specifically for the controls. Rather than creating our own â€œshortcutsâ€, it forced us to use our own code much as any other developer would.</p>
<p>As a result ofÂ this re-development,Â there wereÂ two central issues that we had to address. One was support for Unicode, and the other was multithreading. Unicode support was a fairly easy decision to make. We already had to support it internally because 32-bit ActiveX controls use Unicode. And while it wasnâ€™t considered to be a significant issue ten years ago, we knew that it would be in the future. Multithreading support was a bit more problematic. We knew that it was important in a general sense, however Visual Basic was (for all intents and purposes) a single-threaded language and ActiveX controls use single-threaded apartments. In essence, COM made sure that there would only be one object per thread and that fit nicely with the Windows Sockets API which allows only one outstanding blocking socket operation per thread. With a DLL, we couldnâ€™t make any assumptions about the language it would be used with, or how threads would be managed, if worker threads would be created at all.</p>
<p>We decided on two principal design goals when it came to the SocketTools API. One was to make sure it could be used in both a single-threaded and multithreaded program without requiring any special coding on the part of the developer. Every function had to be designed to be thread-safe, but this introduced another fundamental problem: sockets are not inherently thread-safe. In other words, when you have two threads reading and writing on the same socket, thereâ€™s no guarantee which thread is actually going to read the data, or in what order the data is going to be written. The developer has to use some synchronization mechanism to ensure that thread A is not reading data that thread B expects to read. That tied into the second design goal, which was to make sure the API wouldnâ€™t provide the programmer with just enough rope to hang himself. After all, SocketTools was specifically designed for developers who donâ€™t have a lot of experience with sockets programming. They just want to be able to add features like downloading files or the ability to send emails, without having to worry about all of the low-level details.</p>
<p>This lead to the decision to implement a threading model in the DLLs that was functionally similar to how COM apartment threading works, but with a bit more flexibility. Whenever a handle to a client session is created, it is associated with the thread that created it. The handles that are used with the SocketTools API are really a kind of pseudo-handle that references some internal data structures, along with I/O buffers and the actual socket handle. Whenever the handle is passed to a function, it is dereferenced internally and certain checks are performed depending on the type of function being called. One of those checks is whether the thread that is calling the function is the same as the thread that created the handle. If they donâ€™t match, the error ST_ERROR_NOT_HANDLE_OWNER is returned to the caller. This check isnâ€™t actually performed on all functions; however, any function that deals with I/O on the socket will check thread ownership. Because itâ€™s possible that the developer would want to have one thread initially create the session, but have another thread do the actual work, a mechanism was added where a thread could assume ownership of a handle created by another thread; this is done using the AttachThread function. In many ways, this provided the best of both worlds. Developers could pass client handles to other threads, but they had to explicitly establish ownership which would prevent inadvertent errors in their code that would prove very difficult to debug.</p>
<p>Over time, we have had some developers express some frustration that handles (or class instances, in the case of the .NET classes) cannot be freely passed between threads. Multithreaded languages have become the rule rather than the exception, and itâ€™s really only the legacy languages like Visual Basic 6.0 which donâ€™t have native support for threading. With that in mind, for SocketTools 5.0 we decided to revisit the issue of the thread ownership model that we use. In the end, we have decided that in the interest of making things safer for developers, our implementation was overly restrictive. If the programmer wants to take responsibility for thread synchronization (which would typically have to be done in most cases anyway), then he should be able to without the additional bookkeeping involved in tracking what thread owns a particular client handle at that point in time.</p>
<p>In SocketTools 5.0, when you create a connection you will be able to continue to use the same threading model used in previous versions, or you can choose to specify a â€œfree-threadingâ€ option that tells the class or library that any thread can use that session handle. It is important to keep in mind that if you use this option, you are responsible for synchronizing access to the session yourself. For example, if two threads call the FtpCommand function using the same handle, if you donâ€™t synchronize them you will have no control over which command is actually sent to the server first. This can lead to logical errors in the program which can be very difficult to find in a large program, and itâ€™s often the case that they canâ€™t be reproduced reliably. With the default threading model, you would catch this during testing because one of those threads would get an error indicating that itâ€™s not the handleâ€™s owner. With the free-threading model, that responsibility falls to you. Itâ€™s an advanced option we feel will be of benefit to developers; however we recommend that you continue to use the default threading model whenever possible.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.catalyst.com/archives/9/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

