-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsntp_server.py
More file actions
30 lines (24 loc) · 767 Bytes
/
sntp_server.py
File metadata and controls
30 lines (24 loc) · 767 Bytes
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
30
"""
This module defines classes to handle the communication operations of
the SNTP server, like sending and receiving messages.
"""
from sntp import SNTPMsg
from socket import (
socket,
AF_INET, SOCK_DGRAM,
)
class SNTPSocket (socket):
def __init__ (self):
socket.__init__ (self, AF_INET, SOCK_DGRAM) # UDP/IP socket
self.bind (("", 123)) # Standard port number for SNTP
def recvSNTP (self):
"""
Return a single SNTP request from the socket
"""
return SNTPMsg (* self.recvfrom (1024))
def sendSNTP (self, msg):
"""
Send an SNTP response back to the source of the corresponding request
msg: an SNTPMsg object
"""
self.sendto (msg, msg.addr)