02-28-2011, 01:28 AM
Im currently devloping a plugin to connect to a socket server i just wanted to know if there is a socket module or would i have to use luasockets dll?
(02-28-2011, 01:56 AM)Jockie Wrote: [ -> ]The engine of MCServer is not LUA, so you have to use Java, I think. o.O
class cTCPLink
{
public:
cTCPLink();
~cTCPLink();
bool Connect( _cstring a_Address, unsigned int a_Port );
int Send( _cstring a_Data, unsigned int a_Size, int a_Flags = 0 );
int SendMessage( const _cstring a_Message, int a_Flags = 0 );
void CloseSocket();
protected:
virtual void ReceivedData( char a_Data[256], int a_Size ) = 0;
};local TCPLink = {}
TCPLink.__index = TCPLink
function TCPLink:new()
local t = {}
setmetatable(t, TCPLink)
local w = Lua__cTCPLink:new()
tolua.setpeer(w, t)
w:tolua__set_instance(w)
return w
endTCPLink:ReceivedData( Data, Size )
-- Do stuffs with data
endlocal TCPLink = {}
TCPLink.__index = TCPLink
function TCPLink:new()
local t = {}
setmetatable(t, TCPLink)
local w = Lua__cTCPLink:new_local() -- new_local = Deleted by garbage collector
tolua.setpeer(w, t)
w:tolua__set_instance(w)
return w
end
TCP = TCPLink:new()
if( TCP:Connect("www.mc-server.org", 80) == true ) then
Log("Sending message")
TCP:SendMessage("GET http://www.mc-server.org/\n")
end
function TCPLink:ReceivedData( Data, Size )
Log("Received data: " .. Size )
String = string.sub( Data, 0, Size )
Log( String )
end