Example_Timer_Clock = 0
IRC_Client = -1
IRC_Server = -1
Packet_Construct = ""

IRC_Server = Server("127.0.0.1", 100)

if IRC_Server == -1 then
	print("Failed to bind\n")
else
	print("Bound to port 100")
end

function IRC_Callback(Packet)
	print(Packet.."\n")
end

function Example_Timer() --called every 100mS
	if IRC_Client > -1 then
		if DataAvaliable(IRC_Client) == 0 then
			r = Recv(IRC_Client)
			if r == "\n" or r == "\r" then
				IRC_Callback(Packet_Construct)
				Packet_Construct = ""
			else
				Packet_Construct = Packet_Construct .. r
			end
		end
	else
		if ClientWaiting(IRC_Server) == 0 then
			IRC_Client = Accept(IRC_Server)
			if IRC_Client ~= -1 then
				print("New client accepted\n")
			else
				print("New client rejected\n")
			end
		end
	end
end


function OnThink()
	if tClock() - Example_Timer_Clock > 100 then
		Example_Timer()
		Example_Timer_Clock = tClock()
	end
end