Page 2 of 2

Re: Hi all, Is there a command to send and receive TCP messa

Posted: Fri Mar 30, 2012 5:37 pm
by Administrator
Yes. I like the idea of how my networking works, but I have to admit it is a bit too restrictive at times. I've considered ditching it and just adding encryption functions to MicroMacro so users could use LuaSocket instead.

Re: Hi all, Is there a command to send and receive TCP messa

Posted: Sun Apr 01, 2012 12:47 pm
by vIndie
Was kind of thinking it would be cool if the main parts of MM were written as modules .. keyboard/mouse, memory, etc. then could just use it on standard Lua distribution and mix-and-match the parts you need... guess you can still do that to an extent with MM.

Re: Hi all, Is there a command to send and receive TCP messa

Posted: Sun Apr 01, 2012 2:43 pm
by BillDoorNZ
I could never find any doco on the mm networking stuff - my useless forum searching skills rearing their ugly head :)

So I endd up using LuaSocket too and just created a class for the client side (my server side is all .net C# code).

Code: Select all

require "socket"

CServerLink = class(
	function (self, server, port, readTimeout)
		self.Server = server or settings.profile.options.SERVER_NAME;
		self.Port = port or tonumber(settings.profile.options.SERVER_PORT);
		self.ReadTimeout = readTimeout or 5;
		
		self.Socket = socket.tcp();
		self.Socket:settimeout(readTimeout);
		self.Socket:connect(self.Server, self.Port);
	end
)

function CServerLink:send(data, waitForResult)
	self.Socket:send(data);
	--printf("serverlink:send->"..data.."\n");
	if ((waitForResult) and (waitForResult == true)) then
		local data = "";
		local sIn = self.Socket:receive(1);
		while (sIn ~= "\0") do
			if (sIn) then data = data..sIn; end;
			sIn = self.Socket:receive(1);
		end;
		--printf(data.."\n");	
		return data;
	end;
--	self.Socket:close();
end;

function CServerLink:close()
	self.Socket:close();
end;