LeetSocket – Usage Introduction

Im happy to present you one of our current Projects: Leetsocket.
Leetsocket is a Socket Component written in c# .Net. Its built upon TCP/IP. What makes this Component special is, that you can build Client-Server applications with it, in which you can send any type of data easily without needing to implement any protocolls for sending and receiving or without needing to have any complex knowledge about sockets, working with byte arrays or whatever. Leetsocket sends objects serializing them into byte arrays according its intern binary protocoll. This Component enables you to use many cool features, such as sending files, pausing sendings or even sending things parallely.

The reason why we designed LeetSocket as a “semi-visual” Component for Visual Studio is, that this way, you just can to drag an drop this component on your form, edit essential properties of the Component like Connection/Listening IP and Port and implement the events you wish by just double clicking in the event viewer of the component, everything done visually in design time. But all this can also be done non-visually, by just calling the neccessary Method/Setters etc. manually.

Properties:Events:

In the following, i will describe a very simple usage of LeetSocket in a non-visual Network Application, in detail:
Our intention for this application shall be just to send the String “Hello Server” from Client to Server.
Before being able to send any data, first of all the Server-Side-Socket and the Client-Side-Socket need to be connected with each other. So, the Server-Side has to listen for a new connection, and the Client-Side has to connect to the listening socket. For this purpose, we made manual and automated methods available. So for example, on the Server-Side you either call manually the method startListening() or activate the Property AutoListening, by setting this property to “true”. In AutoListening Mode, if the connection is broken, the Server-Side-Socket will begin to listen automatically again.
Example Usage:

[...]
LeetSocket serverSocket=new LeetSocket();  //new LeetSocket instance
serverSocket.startListening(); //manually start listening
[...]

or

[...]
LeetSocket serverSocket=new LeetSocket();  //new LeetSocket instance
serverSocket.AutoListening=true; // AutoListening Mode being activated
[...]

Equally, on the Client side, it is neccessary, to connect manually or automatically, using the method Connect() or setting the Property AutoConnectSystem to “true”. The manual Connect() call can fail, if the adressed Server doesnt listen, or doesnt even exist, and wont try to connect again. In AutoConnectSystem mode, LeetSocket will try to connect to the given Server-Adress until the connection is established. And if AutoConnectSystem isnt disabled, even if te connection is whyever broken, the our Client-Side-Sockt will begin to try to connect again. The AutoConnect tries happen in default every 3500 miliseconds. This Interval can be changed with the Property AutoConnectInterval:
Example Usage:

[...]
LeetSocket clientSocket=new LeetSocket();  //new LeetSocket instance
clientSocket.ServerIpAsDNS= "127.0.0.1";
clientSocket.ServerPORT= "1234";
clientSocket.Connect(); //manually try to connect
[...]

or

[...]
LeetSocket clientSocket=new LeetSocket();  //new LeetSocket instance
clientSocket.ServerIpAsDNS= "127.0.0.1";
clientSocket.ServerPORT= "1234";
//clientSocket.AutoConnectInterval = 1000; // optionally every second instead of every 3,5 seconds
clientSocket.AutoConnectSystem = true; // manually start listening
[...]

At this point lets assume that listening on the Server-Side and connecting on the Client-Side have been done and the connection is established. LeetSocket gives you even the opportunity to recognize that the Connection is made, with events like “OnConnected”. This event is being invoked when the connection has been made. On the server-side a similiar event exists named “OnBeingConnected”. Easier to implement this event is surely to just create the method for this event by double clicking in the event inspector, as seen in the screenshot above, but below you can see how it can be done manually:
Example Usage:

[...]
public void MyOnConnectMethod(){
MessageBox.Show("We just Connected to the Server!");
}
[...]
clientSocket.OnConnectedEVENT += new MethodInvoker(MyOnConnectMethod);
[...]

Now the client side can even know if the connection is made, and we just need to call the method sendObject for sending the String:

[...]
String ourMessage="Hello Server";
clientSocket.sendObject(ourMessage);
// These two lines could, For Example, stand in the "MyOnConnectMethod", showed above, and the send method would be called, as soon as the connection is done.
[...]

On the Server side, we need to have the event OnReceiveCompleteDataEVENT implemented, because as soon as a sending from Client to Server has ended, this event will be invoked on the Server-Side:

[...]
private void MyOnReceiveCompletedDataMethod(object receivedObject, byte[] bArray)
{
String s = (String)receivedObject;
MessageBox.Show("Server received following Message: " + s);
}
[...]
this.leetSocket1.OnReceiveCompletedDataEVENT += new LeetSocket.LeetSocket.ObjectAndByteArrayDelegate(MyOnReceiveCompletedDataMethod);
[...]

Our example Applikation is finished here.

Many basic usage examples for LeetSocket and the LeetSocket library itself can be found here:

Download

LeetSocket has its own link, up there, in the navigation Menu. See it for getting informed about other features of LeetSocket or for watching the “Build a Simple Chat in 5 Mins” video.

Contact us for questions/bugs.

Have fun!

2 thoughts on “LeetSocket – Usage Introduction

  1. Hi, this is an awesome library for building client server app.

    Well I have 1 doubt, how to connect to a remote server using client app?

    That is say suppose, I have the server app running in India and my friend is running client app in USA… so how do I connect server to client?

    Do I need to write separate code for getting global IP address and assign it to the “ServerIPAsDNS” property dynamically? or is there any other simple workaround for this?

    Kindly help me.

Leave a Reply

Your email address will not be published. Required fields are marked *