- socket = nil
- host = "www.nodemcu.com"
- port = 80
- strOnline = "GET / HTTP/1.1\r\nHost:www.nodemcu.com\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n"
- function connResponse(str)
- print("xxx="..str)
- str = nil
- end
- function connectServer()
- ---------------------------------------------
- conn=net.createConnection(net.TCP, false)
- ---------------------------------------------
- conn:on("connection", function(conn,response) conn:send(strOnline) end)
- conn:on("disconnection", function(conn,response) connectServer() end)
- conn:on("receive", function(conn,response) connResponse(response) end)
- conn:on("sent", function(conn,response) end)
- ---------------------------------------------
- --conn:connect(80,"121.41.33.127")
- conn:connect(80,host)
- ---------------------------------------------
- end
- connectServer()
复制代码 |