Guest User

Untitled

a guest
Jul 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. import socketserver
  2. import socket
  3. import csv
  4.  
  5. from datetime import datetime
  6.  
  7.  
  8.  
  9.  
  10. def clientsocketentry():
  11.  
  12. serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  13. serversocket.bind(('localhost', 8089))
  14. serversocket.listen(5) # become a server socket, maximum 5 connectionn
  15. cont = True
  16. while cont:
  17. connection, addr = serversocket.accept()
  18. while True:
  19. buf = connection.recv(64)
  20.  
  21. if len(buf) == 0: # end of connection
  22. connection.close()
  23. break
  24.  
  25. elif buf == b'killsrv': # request for closing server
  26. connection.close()
  27. serversocket.close()
  28. cont = False
  29. break
  30.  
  31. else:
  32. print (buf)
  33. buf = buf.decode("utf-8")
  34. buf = buf.split(',')
  35. serverLong = buf[0]
  36. print('Longitude:' + '' + serverLong)
  37. serverLat = buf[1]
  38. print('Lattitude:' + '' + serverLat)
  39. serverAlt = buf[2]
  40. print('Altitude:' + '' + serverAlt)
  41. serverTime = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  42. print('Time of Entry:' + ' ' + serverTime)
  43. result = (serverLong, serverLat)
  44.  
  45.  
  46. #write to csv file (Library.csv)
  47. data = [serverTime +' , '+ serverLat +' , '+ serverLong +' , '+ serverAlt]
  48.  
  49. with open('Library.csv', 'a', ) as myfile:
  50. wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
  51. for word in data:
  52. wr.writerow([word])
  53.  
  54. return serverLong, serverLat
  55.  
  56.  
  57. clientsocketentry()
  58.  
  59. import socket
  60. import time
  61. clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  62. clientsocket.connect(('localhost', 8089))
  63. a = '39.163100,-76.899428,0'
  64. clientsocket.send(a.encode('utf-8'))
  65. time.sleep(5)
  66.  
  67. a = '4.2,2.2415,0'
  68. clientsocket.send(a.encode('utf-8'))
  69. time.sleep(5)
  70.  
  71. a = '43454,354354,35435'
  72. clientsocket.send(a.encode('utf-8'))
  73. time.sleep(5)
  74.  
  75. a = '435742.,35.452,52434'
  76. clientsocket.send(a.encode('utf-8'))
  77. time.sleep(5)
  78.  
  79.  
  80. clientsocket.close()
  81.  
  82. import sys
  83.  
  84.  
  85. if sys.version_info[0] == 2:
  86. import Tkinter as tk
  87. else:
  88. import tkinter as tk
  89.  
  90. from PIL import ImageTk
  91.  
  92. from goompy import GooMPy
  93.  
  94. import server
  95.  
  96.  
  97. WIDTH = 1200
  98. HEIGHT = 900
  99.  
  100. result = server.clientsocketentry()
  101. '''LATTITUDE= result[1]
  102. LONGITUDE= result[0]'''
Add Comment
Please, Sign In to add comment