Skip to content

Instantly share code, notes, and snippets.

@olupotd
Created December 2, 2013 07:20
Show Gist options
  • Select an option

  • Save olupotd/7746189 to your computer and use it in GitHub Desktop.

Select an option

Save olupotd/7746189 to your computer and use it in GitHub Desktop.
A simple technique of retrieving all the document keys in a couchdb app
import java.io.*
class Client_Server_Communication
{
private static String msg = "";
private static Socket socket;
private static ServerSocket sever;
static DataInputStream in;
static DataOutputStream out;
public void Server_Version() throws IOException, Exception
{
server = new ServerSocket(7555);
while(true)
{
socket = server.accept();
//create an input stream for receiving data plus an output for writing
in = new DataInputStream(socket.getInputStream());
out = new DataOutputStream(socket.getOutputStream());
msg = in.readUTF();
System.out.println("Client Says: "+msg);
//send feedback to client
out.writeUTF("Hello Client");
out.flush();
in.close();
out.close();
}
}
public void Client_Version()
{
Socket client = new Socket("localhost", 7555);
DataInputStream in = new DataInputStream(client.getInputStream());
DataOutputStream out = new DataOutputStream(client.getOutputStream());
System.out.println("Sendin request to server");
out.writeUTF("Hello Server");
out.flush();
System.out.println("Server Response: "+in.readUTF());
in.close();
out.close();
}
}
import os
print "Checking for couchdb in your system"
got = os.popen('whereis couchdb').read()
if not got.split(':')[1:2]:
print "Installing couchdb on your system"
os.system('sudo pip install couchdb')
print ""
import couchdb
#declare a server url
couch = couchdb.Server('http://url_to_server:port')
db = couch['database_name']
#to print all the ids in the databse
for id in db:
print id
print "Done...."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment