Click here to Skip to main content
11,806,575 members (44,680 online)
Click here to Skip to main content

Sending Binary Data using Sockets

, 25 Jan 2005 65.6K 678 53
Rate this:
Please Sign up or sign in to vote.
An article on file transfer using sockets.



I'll demonstrate and provide some very basic classes that can be used as a base for some client/server applications.


When searching the internet for some code that can send files over the net, I was disappointed. All I could find where some chat like programs and very few articles on file transfer. Well, here's my attempt to change that.

Using the code

I created very basic classes which are very similar to the ones you can find on the net, but mine are more elegant (at least I think so). I created some events which make the usage of these classes very easy and straightforward.

To create a client, just create it like any other object:

private INPClient _client;

// in the initialisation
_client = new INPClient("",11000);

// to send a file do

Creating a server to receive a file, is quite simple.

private INPServer _server;

// in the initialisation

_server = new INPServer("",11000);

_server.ClientConnected+=new NetworkEventHandler(_server_ClientConnected);
_server.ClientDisConnected +=
                new NetworkEventHandler(_server_ClientDisConnected);
_server.DataRecieved+=new NetworkEventHandler(_server_DataRecieved);
_server.RecieveCompleted+=new EventHandler(_server_RecieveCompleted);

// and in the body of the code you chould implement thes functions aswell eg:

private void _server_ClientConnected(object sender, NetworkEventArgs ne)
    txtData.Text+= ne.Info.Socket.RemoteEndPoint.ToString()
                + " connected.\r\n";

private void _server_ClientDisConnected(object sender, NetworkEventArgs ne)
    txtData.Text+= ne.Info.Socket.RemoteEndPoint.ToString()
                + " disconnected.\r\n";

private void _server_DataRecieved(object sender, NetworkEventArgs ne)
    txtData.Text += "\r\nRECIEVING DATA FROM "
                 + ne.Info.Socket.RemoteEndPoint.ToString() +".";

private void _server_RecieveCompleted(object sender, EventArgs e)
    txtData.Text += "\r\nRECIEVING DATA COMPLETED FROM "
                 + ne.Info.Socket.RemoteEndPoint.ToString() +".";

// to start the server

// to stop the server

If you want to use this code to create a server, you should inherit from the serverbase class and implement the protocol in a new class. The INPServer is a sample of this.

When creating software nowadays, it's not so important if you can do it, it is how you do it that is important. When solving a problem, it is important to not just find "a solution", it is important to find "the right solution".

Points of Interest

I would like comment on this article since it is my first one but I would like to post some more. I am an expert on component / control development. Maybe there are some cool things you'd like to see in an article. Please let me know if you find spelling errors. Please post about them or let me know until the buy.


I created this project in January 2005. If I find the time, I might add a second article on protocol implementation.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Belgium Belgium
No Biography provided

You may also be interested in...

Comments and Discussions

General[Message Deleted] Pin
it.ragester2-Apr-09 21:50
memberit.ragester2-Apr-09 21:50 
QuestionSome clarification please! Pin
@Jim3-Jul-07 7:35
member@Jim3-Jul-07 7:35 
Questionhow can i control the saving of the sended file in server side? Pin
fcis200722-Dec-06 6:44
memberfcis200722-Dec-06 6:44 
AnswerRe: how can i control the saving of the sended file in server side? Pin
Fouad Mahmoud22-Dec-06 15:02
memberFouad Mahmoud22-Dec-06 15:02 
GeneralGreat idea, but needs work Pin
Will Gray1-Jun-05 7:14
memberWill Gray1-Jun-05 7:14 
GeneralDo write an article on protocol implemetation Pin
BrazilianDudi26-Jan-05 11:31
memberBrazilianDudi26-Jan-05 11:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151002.1 | Last Updated 26 Jan 2005
Article Copyright 2005 by engine252
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid