<commit_before># README #


### What is "TheTunnel" for? ###

It is an implementation of flexible session + presentation-level protocol on .Net (mono)

This protocol is designed for a using via  duplex transport level protocol with guaranteed delivery. 
  Transport level protocol witch are using by theTunnel can be streaming-type. Actualy TheTunnel was tested only on TCP/IP at currently moment

  TheTunnel Provides:
  
*  Large(or HUGE) data - packets delivery (more than 10 mb).
*  Working va TCP/Ip protocol
*  Simultaneous delivery of multiple data-packets
  	 (you can send a several files and whrite short message to client simultaneous, via one tcp/port for example)
*  Immitation for Remote method call. You can call method on other side and wait for its returns
*  Work with protobuf at serializing/desirializing data.
*  Functionality for easy definding your own message type, with  
  Protobuf or your own Serialize and Deserialize method for each messageType.

## .net example ##

Simple dialog implementation:

~~~c#
  	public class CordContractExample: ICordContract{
		[InCord("STXT")]
		public void SetText(string text){
			//...Handling remote message here
		}

		[InCord("G_UI")]
		public UserInfo GetUserInfo(int id){
			//...Handling remote call here
			return new UserInfo(){ Name = "Bzingo", Id = id} ;
		}

		[OutCord("R_UI")]
		//Call remote method
		public Func<int, UserInfo> GetLasUserInfo{ get; set;}

		//Wrapper of remote method call
		public UserInfo GetLastUserInfoWrapper(int id){
			return GetLasUserInfo (id);
		}
		//Calling at disconnection
		public void OnDisconnect (DisconnectCause сause){
			Console.WriteLine (":( Connection was closed");
		}
		//Raise it, when you wanna close a connection
		public event Action<ICordContract> PleaseDisconnect;
	}

	[ProtoBuf.ProtoContract]
	public class UserInfo{
		[ProtoBuf.ProtoMember(1)] public string Name{get;set;}
		[ProtoBuf.ProtoMember(2)] public string Surname{ get; set;}
		[ProtoBuf.ProtoMember(3)] public int Id{get;set;}
	}
~~~

## also ##
     
* Currently this project is in alpha state, so i've got no help or any examples. 

*  This project shoud be done in a mounth because of job projects.

*  Specification of TheTunnel protocol will be posted later.

*  C - version of this protocol implementation, also will be posted later.

 If someone is interested in this kind of protocol - please let me know.<commit_msg>Add a tested code example to read me<commit_after># README #


### What is "TheTunnel" for? ###

It is a .Net implementation of lightweight data presentation/transmition protocol.

This protocol is designed for a using over TCP tranport.

  TheTunnel Provides:
*  Intuitive interface 
*  Large(or HUGE) data - packets delivery (more than 10 mb).
*  Simultaneous delivery of multiple data-packets
  	 (you can send a several files and whrite short message to client simultaneous, via one tcp/port for example)
*  Immitation for Remote method call. You can call method on other side and wait for its returns
*  Work with protobuf at serializing/desirializing data.
*  Functionality for easy definding your own message type, with Protobuf or build-in data types

## .net example ##

Simple chat implementation on TT:

~~~c#
//////////////////
//[Client-side]//
////////////////
	
public class ClientContract{
	[Out(1)] public Func<string,string,bool> SendMessage{get;set;}

	[In(2)]  public void ReceiveMessage(DateTime timeStamp, string sender, string message){
			Console.WriteLine ("["+timeStamp.ToShortTimeString()+"]" + sender + ": " + message);
	}
}
	
static void Main(string[] args)
{
	TcpClientTunnel client = new TcpClientTunnel ();
	ClientContract contract = new ClientContract ();
		
	Console.WriteLine ("Connecting to 172.16.31.34..");
	client.Connect (new IPAddress (new byte[]{ 172, 16, 31, 34 }), 1234, contract);
	Console.WriteLine ("Succesfully to connected!");

	while (true) {
		var msg = Console.ReadLine ();
	        contract.SendMessage ("tmt", msg);
	}
}
	
	
///////////////////
//[Server-side]///
/////////////////
	
public class ServerContract{
	[In(1)]  public bool MsgFromClient(string nick, string message){
		Console.WriteLine ("["+timeStamp.ToShortTimeString()+"] " + nick + ": " + message);
		return true; //we are always happy to take a message
	}
		
	[Out(2)] public Action<DateTime,string,string> SndMsg{get;set;}
}
	
static void Main(string[] args)
{
	TcpServerTunnel<ServerContract> server = new TcpServerTunnel<ServerContract>();
	
	server.OpenServer (IPAddress.Any, 1234);
	
	server.OnConnect+= (srv, contract) => {
		Console.WriteLine("Client connected"); 
		contract.SndMsg(DateTime.Now,"serv","Welcome to the tunnel");
	};
	
	while (true) {
		var msg = Console.ReadLine ();
		foreach (var contract in server.Contracts)
			contract.SndMsg (DateTime.Now, "serv", msg);
	}
}
	
	
~~~

Clear, isn't it?

In case of this primitive chat, protocol implementation is also very clear:

~~~

 1) SendMessageToServer  timestamp:UTC nick:UTF16    message:UTF16
 
 2) SendMessageToClient  nick:UTF16  message:UTF16 -> INT8 //will not lie to yourself - bool is always byte

~~~


## also ##
     
  Currently i'm testing convenience of .Net implementation and specifying serialization and deserialization format in some complex cases. If someone is interested in this kind of protocol, or wanna participate in its development - please let me know.
{'fraction_non_alphanumeric': 0.11014115898959881, 'fraction_numerical': 0.008915304606240713, 'mean_word_length': 3.86449864498645, 'pattern_counts': {'":': 3, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7402735', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1535, 'n_words': 603}