var net = require('net');

module.exports = function(){

	var Client = null
	var DataAll = ""
	var Boundary = "--BAS-BOUNDARY--"
	    
	this.Start = function(Pid, OnData)
	{

		Client = net.connect("\\\\.\\pipe\\basembeddedpipes18.10.0" + Pid, function() {
    		
		})

		Client.on('data', function(Data) {
			DataAll += Data
			var DataSplit = DataAll.split(Boundary)
			var DataLast = DataSplit[DataSplit.length - 1]
			if(DataLast.length == 0)
			{
				DataAll = ""
			}else
			{
				DataAll = DataLast
			}
			DataSplit.pop()

			for(var i = 0;i<DataSplit.length;i++)
			{
				OnData(DataSplit[i])	
			}
    		
		});

	}
	this.Write = function(Text)
	{
		Client.write(Text + Boundary)
	}

}


