Permalink
Browse files

slowsink.py now acts as client too.

  • Loading branch information...
chenshuo committed Jan 11, 2013
1 parent 6d190e7 commit 9f217126c945408ca0ede205357f230257f52765
Showing with 21 additions and 8 deletions.
  1. +1 −0 README
  2. +20 −8 examples/wordcount/slowsink.py
View
1 README
@@ -1,5 +1,6 @@
Muduo is a multithreaded C++ network library based on
the reactor pattern.
It runs on Linux with kernel version >= 2.6.28.
http://code.google.com/p/muduo/
Copyright (c) 2010, Shuo Chen. All rights reserved.
@@ -2,6 +2,7 @@
import os, socket, sys, time
host = ''
port = 2007
if len(sys.argv) > 1:
@@ -12,16 +13,27 @@
BUFSIZE = int(bps/10) # sleep 100ms at full speed
print "Mbytes/s =", mps
print "listening on port", port
listen_address = ("", port)
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_socket.bind(listen_address)
server_socket.listen(5)
if len(sys.argv) > 3:
host = sys.argv[2]
port = int(sys.argv[3])
print "connecting to %s:%d" % (host, port)
else:
print "listening on port", port
if host:
client_socket = socket.create_connection((host, port))
print "connected to", client_socket.getpeername()
else:
listen_address = ("", port)
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_socket.bind(listen_address)
server_socket.listen(5)
(client_socket, client_address) = server_socket.accept()
print "got connection from", client_address
(client_socket, client_address) = server_socket.accept()
print "got connection from", client_address
start = time.time()
total_size = 0
dot = bps

0 comments on commit 9f21712

Please sign in to comment.