local flower = flower
-- LuaSocket should come with zerobrane
local socket = require("socket")

NetworkFrameworkEntity = flower.class()

function NetworkFrameworkEntity:init(t)
    self.theirIP = t.theirIP or "localhost"
    self.port = t.port or 48310
    self:run()
end

function NetworkFrameworkEntity:run()
    self.server, self.servError = socket.bind("*", self.port)
    if self.server then
        print("Network connection info:")
        print(self.server:getsockname())
        
        self.server:settimeout(15)
        self.client, self.servError = self.server:accept()
    else
        self.client, self.servError = socket.connect(self.theirIP, self.port)
    end
        
    if self.client then
        self.client:settimeout(0)
    end
end

function NetworkFrameworkEntity:stop()
    if self:isConnected() then
        self.client:close()
        
        if self.server then
            self.server:close()
        end
    end
    
    self.client = nil
    self.server = nil
end

function NetworkFrameworkEntity:isConnected()
    if self.client then
        return true
    end
    
    return false, (self.servError or "Unknown error")
end

function NetworkFrameworkEntity:talker(text)
    if self:isConnected() then
        assert(self.client:send(text .. "\n"))
    end
end

function NetworkFrameworkEntity:listener()
    if self:isConnected() then
        local l, e = self.client:receive()
        return l
    end
end
local flower = flower
-- LuaSocket should come with zerobrane
local socket = require("socket")

NetworkFrameworkEntity = flower.class()

function NetworkFrameworkEntity:init(t)
    self.theirIP = t.theirIP or "localhost"
    self.port = t.port or 48310
    self:run()
end

function NetworkFrameworkEntity:run()
    self.server, self.servError = socket.bind("*", self.port)
    if self.server then
        print("Network connection info:")
        print(self.server:getsockname())
        
        self.server:settimeout(30)
        self.client, self.servError = self.server:accept()
    else
        self.client, self.servError = socket.connect(self.theirIP, self.port)
    end
        
    if self.client then
        self.client:settimeout(0)
    end
end

function NetworkFrameworkEntity:stop()
    if self:isConnected() then
        self.client:close()
        
        if self.server then
            self.server:close()
        end
    end
    
    self.client = nil
    self.server = nil
end

function NetworkFrameworkEntity:isConnected()
    if self.client then
        return true
    end
    
    return false, (self.servError or "Unknown error")
end

function NetworkFrameworkEntity:talker(text)
    if self:isConnected() then
        assert(self.client:send(text .. "\n"))
    end
end

function NetworkFrameworkEntity:listener()
    if self:isConnected() then
        local l, e = self.client:receive()
        return l
    end
end
Increase timeout limit. Some windows computers are quite slow in connecting.
Increase timeout limit.
Some windows computers are quite slow in connecting.
