Skip to content

Instantly share code, notes, and snippets.

@takahub1
Last active February 24, 2017 05:10
Show Gist options
  • Save takahub1/6596bd0fe9131430cba45d11af975292 to your computer and use it in GitHub Desktop.
Save takahub1/6596bd0fe9131430cba45d11af975292 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import socket
import subprocess #for unix command
import time #for sleep
import random #for random number
def main():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("192.168.10.103", 51007)) # 指定したホスト(IP)とポートをソケットに設定
print "waiting for connection..."
s.listen(1) # 1つの接続要求を待つ
soc, addr = s.accept() # 要求が来るまでブロック
print("Conneted by"+str(addr)) #サーバ側の合図
while (1):
if raw_input() == "q": # qが押されたら終了
soc.close()
break
subprocess.call('make', shell=True) #update image
time.sleep(1)
soc.send("1")
time.sleep(1)
soc.send(str(random.randint(3,4)))
time.sleep(1)
soc.send(str(random.randint(3,4)))
# soc.send("4")
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment