-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.py
31 lines (28 loc) · 904 Bytes
/
Server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import socket
import numpy as np
import struct
from time import sleep
import csv
localIP = "192.168.1.2"
localPort = 20001
bufferSize = 1024
# Create a datagram socket
UDPServerSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
# Bind to address and ip
UDPServerSocket.bind((localIP, localPort))
print("UDP server up and listening")
# Listen for incoming datagrams
bytesAddressPair = UDPServerSocket.recvfrom(bufferSize)
message = bytesAddressPair[0]
address = bytesAddressPair[1]
print(address)
while(True):
f = open('log.txt','a')
timestamp = str(UDPServerSocket.recvfrom(bufferSize)[0]).replace("'",'').replace('b','').replace('\\n','\r\n')
values = str(UDPServerSocket.recvfrom(bufferSize)[0]).replace("'",'').replace('b','').replace('\\n','\r\n')
print(timestamp)
print(values)
f.write(timestamp)
f.write(values)
sleep(0.7)
f.close()