This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ErwinOlie's profile picture

RabbitTcp - Bridge to Tcp Connections

Started by ErwinOlie, 09 November 2015 - 06:04 PM
ErwinOlie #1
Posted 09 November 2015 - 07:04 PM
None seemed to be interested, closed and servers offline, sorry D:
PM me if u realy need/want this, then i might put the servers online again, special for you ;)/>

Hi there! Because none seemed to be intrested in my webbrowser, i've made something new! =)

It's a bridge in cc, which allows anyone to create a tcpclient :)/>

Picture: (getting a mc server status)
Spoiler

Example of use: (getting a mc server status)
Spoiler

os.loadAPI("RabbitTcp");
function toString(bytes)
  result = "";
  for i, obj in ipairs(bytes) do
	if true then
   result = result .. string.char(tonumber(obj));
end
  end
  return result;
end
client = RabbitTcp.RabbitTcp("server.hobbelcraft.nl", "25565");
client:send({ 31, 0, 47, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 });
client:send({ 1, 0 });
print(toString(client:read()))
client:close();

Source of the api (v1.0):
Spoiler

RabbitTcp = {};
RabbitTcp.__index = RabbitTcp;

setmetatable(RabbitTcp, {
  __call = function (class, host, port)
	local self = setmetatable({}, class);
	self.id = http.get("http://direct.erwinolie.nl:8080/new/" .. host .. "/" .. port).readLine();
	return self;
  end,
})

function RabbitTcp:send(bytes)
  http.get("http://direct.erwinolie.nl:8080/" .. self.id .. "/send/" .. table.concat(bytes, ","));
end

function RabbitTcp:close()
  http.get("http://direct.erwinolie.nl:8080/" .. self.id .. "/close");
end

function RabbitTcp:read()
  result = {};
  data = http.get("http://direct.erwinolie.nl:8080/" .. self.id .. "/read");
  while true do
line = data.readLine()
if (line == nil or line == "") then
break;
else
table.insert(result, line);
end
  end
  return result;
end

Feedback? :)/>
Edited on 05 December 2015 - 10:37 PM
ardera #2
Posted 09 November 2015 - 07:55 PM
Nice!
Creator #3
Posted 09 November 2015 - 08:39 PM
Not only nice, this is excellent!
Konlab #4
Posted 13 November 2015 - 03:57 PM
Very intresting. So you use the http API for tcp. How fast is it?
Creeper9207 #5
Posted 03 December 2015 - 05:54 AM
Can this keep a connection alive? If it does that would be absolutely amazing
Edited on 03 December 2015 - 04:55 AM