imageTcpClient is a class in .NET Framework which “provides simple methods for connecting, sending, and receiving stream data over a network”. TcpClient hides the details of working with sockets and it’s a simple way to open connections and work with TCP. Unfortunately, TcpClient is not available in Windows Phone version of .NET Framework.

SocketEx.TcpClient – Unofficial, only little tested TcpClient for Windows Phone

SocketEx.TcpClient is a MIT-licensed TcpClient for Windows Phone which aims to make working with Windows Phone sockets easy. Compared to the TcpClient in full .NET Framework, SocketEx.TcpClient isn’t 100% compatible and some of the features aren’t implemented at all.

Please note that the library works in a synchronous blocking mode. This means that if you use the TcpClient directly from the UI-thread, you will block the UI from updating.

The library hasn’t gone through an exhaustive testing so there may be issues. The code is based on the “Crystalbyte Networking for Silverlight” project, available from the CodePlex. Almost all of the code is from that neat library, but I adjusted it a little to get it working with Windows Phone and fixed out some threading issues.

The usage

With SocketEx.TcpClient you don’t work with the low-level Socket and SocketAsyncEventArgs-classes. Instead you create a new TcpClient and then operate its stream using either a StreamReader or a StreamWriter. This is easier than it sounds.

I’ve previously written about how to operate with the built-in Socket and SocketAsyncEventArgs classes.

Now, let’s do those same examples with SocketEx.TcpClient.

SocketEx.TcpClient – How To Open a Connection

We can open the connection by passing the server address and server port as parameters to TcpClient.

            var serverAddress = "";
            var serverPort = 80;

            var connection = new TcpClient(serverAddress, serverPort);

SocketEx.TcpClient – How To Receive a Message

To read a message we need a StreamReader.

            var connection = CreateConnection();
            var stream = connection.GetStream();

            var reader = new StreamReader(stream);

            string message;
            while ((message = reader.ReadLine()) != null)

SocketEx.TcpClient – How To Send a Message

To write a message we need a StreamWriter.

            var connection = CreateConnection();
            var stream = connection.GetStream();

            using (var writer = new StreamWriter(stream))
                var request = "GET / HTTP/1.1rnHost: " + serverAddress + "rnConnection: Closernrn";


Project’s home and sample app

The SocketEx.TcpClient lives in GitHub. The repository contains the TcpClient and a sample app which uses it.


Easiest way to get started with SocketEx is to use NuGet. The package name is SocketEx.


The binary version of SocketEx is available for download from GitHub.


Comment by louis vuitton glasses

louis vuitton glasses...

Thank you for the good writeup. It in fact was a amusement account it. Look advanced to far added agreeable from you! However, how could we communicate?...

Comment by win 7 ultimate 64 bit key

win 7 ultimate 64 bit key...

Hi there, just wanted to tell you, I enjoyed this blog post. It was funny. Keep on posting!...

Comment by Alexey Gapchenko

Is there any version of Socketex for WP8?

Comment by Alexey Gapchenko

I just changed target framework to WP8 and seems it should work fine. Thanks a lot for this lib!

Comment by Mikael Koskinen

Sorry for the really long delay in the reply! As you mentioned, there's no WP8 version of the lib but the code should work as is with WP8. As long as the lib targets the WP 7.1 (7.5), you should be able to reference the DLL from both a WP7.5 and a WP8 app.

Comment by Henrik Eriksson

Hi Mikael! This library is really awsome, makes networking much easy! ( Like java )
You said it was MIT-licensed, is it free to use? Even if i upload a app that uses SocketEx on WP Store?

Comment by Mikael Koskinen

Hi Henrik,

Yes, it's free and open :) The library uses the same license as the Caliburn.Micro does so you can submit apps using SocketEx to the store. There's already few apps out there using the library.

Comment by

Hi there, just wanted to tell you, I loved this article. It was helpful. Keep on posting!...

Comment by Nordstrom promo Code 2014

Nordstrom promo Code 2014...

Hello, just wanted to say, I enjoyed this post. It was helpful. Keep on posting!...

Comment by Nordstrom Coupon Code

Nordstrom Coupon Code...

Hi there, just wanted to mention, I liked this blog post. It was funny. Keep on posting!...

Comment by ArcheAge


You started!...