diff --git a/ptypes-tcp/server.cpp b/ptypes-tcp/server.cpp index de7c688..8bebe78 100644 --- a/ptypes-tcp/server.cpp +++ b/ptypes-tcp/server.cpp @@ -31,8 +31,8 @@ void servermain(ipstmserver& svr) string host = phostbyaddr(client.get_ip()); if (isempty(host)) host = iptostring(client.get_ip()); - - client.putline("Hello, the current timestamp is - " + itostring(now())); + int timestamp = (now() - _unixepoch) / 1000; + client.putline("Hello, the current timestamp is - " + itostring(timestamp)); client.flush(); pout.putf("%t greeting received from %s (%a)\n", diff --git a/python-tcp/client.py b/python-tcp/client.py new file mode 100644 index 0000000..9438b26 --- /dev/null +++ b/python-tcp/client.py @@ -0,0 +1,9 @@ +import socket + +s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +s.connect(("127.0.0.1", 8085)) +s.send("Hello") +data = s.recv(1024) +s.close() + +print data \ No newline at end of file diff --git a/python-tcp/server.py b/python-tcp/server.py new file mode 100644 index 0000000..86dd45f --- /dev/null +++ b/python-tcp/server.py @@ -0,0 +1,23 @@ +import time +import socket +import thread + +s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +s.bind(("127.0.0.1", 8085)) +s.listen(1) + +def func(): + while True: + conn, addr = s.accept() + data = conn.recv(1024) + conn.send("Hello, the current timestamp is - " + str(int(time.time()))) + conn.close() + +thread.start_new_thread(func, ()) +while True: + pass +#while True: +# conn, addr = s.accept() +# data = conn.recv(1024) +# conn.send("Hello, the current timestamp is - " + str(int(time.time()))) +# conn.close() \ No newline at end of file diff --git a/python-thread/threadexample.py b/python-thread/threadexample.py new file mode 100644 index 0000000..0ccaf7c --- /dev/null +++ b/python-thread/threadexample.py @@ -0,0 +1,19 @@ +import threading +import sys + +class mythread(threading.Thread): + def run(self): + for i in range(0, 10): + sys.stdout.write(str(i) + "\n") + +try: + thread1 = mythread() + thread2 = mythread() + + thread1.start() + thread2.start() + + thread1.join() + thread2.join() +except: + print "Could not create threads!" \ No newline at end of file