Created
April 23, 2010 21:39
-
-
Save kumagi/377220 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import msgpack | |
import socket,struct,sys,time | |
SET=0 | |
GET=1 | |
DELETE=2 | |
FOUND=3 | |
DONE=4 | |
NONE=5 | |
class msgpack_client(object): | |
def __init__(self,port,ip): | |
self.port=9090 | |
self.ip='127.0.0.1' | |
self.fd = socket.socket(socket.AF_INET,socket.SOCK_STREAM) | |
self.fd.connect((self.ip,self.port)) | |
def set(self,key,value): | |
packer = msgpack.packb([0,key,value]) | |
if self.fd: | |
pass | |
else: | |
print "connect before send\n" | |
return | |
self.fd.send(packer) | |
recv_tuple = self.fd.recv(1024) | |
status = msgpack.unpackb(recv_tuple); | |
return status == DONE | |
if __name__ == '__main__': | |
cl = msgpack_client(9090,'127.0.0.1') | |
i=0 | |
while(1): | |
status = cl.set("foo"+'%d'%i,"bars"); | |
#time.sleep(0.2) | |
if(status): | |
print "ok %d"%i | |
i = i + 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment