Hi,
I want to make a UDP client server application that is conform to
RFC868 (Time protocol). Both the UDP client and UDP server are in a
test phase.
The question is: when I add "svrsocket.send to(resultaat, (ip, port))"
in the UDP server, my application closes while running. When I leave
it away, it works fine. I really need this statement as the purpose is
that a client sends sth to the server and the server sends back the
time ticks.
Anybody an idea how I can modifu my client/server so that it works?
Regards,
Wim
Here is the server:
# UDP server example
import time
import socket
import string
import string
class Tijd:
def __init__(self, hours=0,minutes =0,seconds=0):
self.hours=hour s
self.minutes=mi nutes
self.seconds=se conds
def aantal_seconden (self):
x = time.time()
y=(1970, 1, 1, 1, 0, 0, 0, 0, 0)
y=time.mktime(y )
resultaat=x-y
return resultaat
if __name__=="__ma in__":
tijd=Tijd()
resultaat=tijd. aantal_seconden ()
print 'resultaat',res ultaat
port=37
svrsocket = socket.socket(s ocket.AF_INET, socket.SOCK_DGR AM)
svrsocket.bind( ('', port))
hostname = socket.gethostn ame()
ip = socket.gethostb yname(hostname)
print 'TOD server is at IP adress: ', ip
tijd=time.ctime ()
tijd=string.spl it(time.ctime() )
print 'The current time is', tijd[3]
print 'Listening for TOD-requests on port %s ...' %port
while 1:
data, address = svrsocket.recvf rom(256)
print 'Received a TOD-request from modem with IP-address %s'
%address[0]
print 'Sending back the time to modem with
IP-address',addres s[0]
print "time", resultaat
svrsocket.sendt o(resultaat, (ip, port))
And here is the client:
# UDP client example
import socket
port=37
clisocket = socket.socket(s ocket.AF_INET, socket.SOCK_DGR AM)
while 1:
data = raw_input("Type something: ")
if data:
clisocket.sendt o(data, ("127.0.0.1" , port))
else:
break
s.close()
I want to make a UDP client server application that is conform to
RFC868 (Time protocol). Both the UDP client and UDP server are in a
test phase.
The question is: when I add "svrsocket.send to(resultaat, (ip, port))"
in the UDP server, my application closes while running. When I leave
it away, it works fine. I really need this statement as the purpose is
that a client sends sth to the server and the server sends back the
time ticks.
Anybody an idea how I can modifu my client/server so that it works?
Regards,
Wim
Here is the server:
# UDP server example
import time
import socket
import string
import string
class Tijd:
def __init__(self, hours=0,minutes =0,seconds=0):
self.hours=hour s
self.minutes=mi nutes
self.seconds=se conds
def aantal_seconden (self):
x = time.time()
y=(1970, 1, 1, 1, 0, 0, 0, 0, 0)
y=time.mktime(y )
resultaat=x-y
return resultaat
if __name__=="__ma in__":
tijd=Tijd()
resultaat=tijd. aantal_seconden ()
print 'resultaat',res ultaat
port=37
svrsocket = socket.socket(s ocket.AF_INET, socket.SOCK_DGR AM)
svrsocket.bind( ('', port))
hostname = socket.gethostn ame()
ip = socket.gethostb yname(hostname)
print 'TOD server is at IP adress: ', ip
tijd=time.ctime ()
tijd=string.spl it(time.ctime() )
print 'The current time is', tijd[3]
print 'Listening for TOD-requests on port %s ...' %port
while 1:
data, address = svrsocket.recvf rom(256)
print 'Received a TOD-request from modem with IP-address %s'
%address[0]
print 'Sending back the time to modem with
IP-address',addres s[0]
print "time", resultaat
svrsocket.sendt o(resultaat, (ip, port))
And here is the client:
# UDP client example
import socket
port=37
clisocket = socket.socket(s ocket.AF_INET, socket.SOCK_DGR AM)
while 1:
data = raw_input("Type something: ")
if data:
clisocket.sendt o(data, ("127.0.0.1" , port))
else:
break
s.close()
Comment