如何使用串行标记Python服务器文件

时间:2016-04-10 17:40:08

标签: python sockets arduino

我有一个问题,是否可以使用Python的套接字模块直接连接到IP。我在本地测试了下面的代码,一切正常,但在联机时遇到问题(即使我的主机支持套接字)。基本上,我在我的计算机上运行一个server.py文件,该文件使用套接字来侦听传入连接。在按钮单击中,客户端将要求服务器获得运行某些arduino代码的权限。这在本地工作,但是当我尝试将其联机时,它不会。我可能在这里理论上缺少一些东西,或者做一些需要比我更多知识的东西。

简而言之,我的问题是,如何从网上定位我计算机上的特定文件?

# I've imported bottle here

import socket
host = '192.XXX.X.XXX' <--this being my computer's IP? Is this possible?
port = 8080

# I have a form that runs this def
# the go is just a way to communicate with the server file, which         
# runs the arduino code

@route('/systems', method='POST')
def syson():
    our_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    our_socket.connect((host, port))
    message = "turn_on_arduino"
    our_socket.send(bytes(message,'UTF-8'))
    reply = our_socket.recv(1024)
    return bottle.redirect("/systems")

谢谢

0 个答案:

没有答案