os-70-350

os-70-350 Commit Details


Date:2013-12-15 23:12:05 (11 years 8 months ago)
Author:Natalie Adams
Branch:master
Commit:2e1e315e2939be19172ae2bb92843646ba9ffbe1
Parents: 8027db320952c6da7ca80d17ef31fb8e9dfa1a1d
Message:Adding python thread and TCP examples Updating ptypes TCP example

Changes:

File differences

ptypes-tcp/server.cpp
3131
3232
3333
34
35
34
35
3636
3737
3838
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",
python-tcp/client.py
1
2
3
4
5
6
7
8
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
python-tcp/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
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()
python-thread/threadexample.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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!"

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.25760s using 14 queries.