Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

one UDP and one TCP servers ? #1559

Closed
vadimostanin opened this issue Oct 24, 2016 · 2 comments
Closed

one UDP and one TCP servers ? #1559

vadimostanin opened this issue Oct 24, 2016 · 2 comments

Comments

@vadimostanin
Copy link

Is it possible to have one udp and one tcp server?
I want to make discovering of ESP by UDP, and make data transferring by TCP

uart.setup(0,9600,8,0,1)

print("Start ESP8266")

wifi.setmode(wifi.STATION)
wifi.sta.config("essid","password")
wifi.sta.connect()

tmr.alarm(0, 1000, 1, function()
    if wifi.sta.getip() == nil then
        print("Connecting to AP...")
    else
        print('IP: ',wifi.sta.getip())
        registerServer()
        tmr.stop(0)
    end
end)

function registerServer()
    if srv ~= nil then
      srv:close()
    end
    if srv2 ~= nil then
      srv2:close()
    end
    print("before create server")
    srv = net.createServer(net.UDP)
    srv:on("receive",
                function(socket, request)
                    print(request)                    
                    socket.close()
                end)
    srv:listen(33249)

    srv2 = net.createServer(net.TCP)
    srv2:listen(33248,function(conn)
      conn:on("receive",function(socket,request)
        print( request )
        socket.close()
      end)
      conn:on("sent",function(conn) conn:close() end)
    end)
end
@vadimostanin vadimostanin changed the title one UDP and one TCP servers one UDP and one TCP servers ? Oct 24, 2016
@NicolSpies
Copy link

Hi, please refer to #1080 where your question is addressed

@marcelstoer
Copy link
Member

Is it possible to have one udp and one tcp server?

Yes. For further user support consider #1010.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants