connecting to server process via sockets

Поиск
Список
Период
Сортировка
От Randall Smith
Тема connecting to server process via sockets
Дата
Msg-id 4288B8E3.3090906@tnr.cc
обсуждение исходный текст
Ответы Re: connecting to server process via sockets  (John DeSoi <desoi@pgedit.com>)
Re: connecting to server process via sockets  (Douglas McNaught <doug@mcnaught.org>)
Список pgsql-general
For fun and learning, I would like to connect to the Postgresql backend
and issue queries using sockets.  I'm using Python's socket module.  I'm
new to socket programming, but I'm experienced with Python and
Postgresql.  I've been using the JDBC driver and the online
documentation as a guide, but I'm afraid my ignorance has led me to
failure thus far.

This is what I think I understand.

1.  Send the startup message as such.
    a.  length of message.
    b.  protocol major (3)
    c.  protocol minor (0) (don't know what this is).
    d.  message
    e.  send 0 (Don't know why?)

O.K.  Here I show my ignorance.

#!/usr/bin/python

import socket

# Connection string
cnstring = 'user=randall, database=dws, client_encoding=UNICODE,
DateStyle=ISO'  # This just wrapped in my email.
msg_len = str(len(cnstring))
protocol_major = '3'
protocol_minor = '0'

pgsocket = socket.socket()
pgsocket.connect(('localhost', 5432))
pgsocket.send(msg_len)
pgsocket.send(protocol_major)
pgsocket.send(protocol_minor)
pgsocket.send(cnstring)
pgsocket.send('0')
pgsocket.close()


When I run this, this is what shows up in the logs.

2005-05-16 10:11:34 [2638] LOG:  connection received: host=127.0.0.1
port=42607
2005-05-16 10:11:34 [2638] LOG:  invalid length of startup packet

Please do not recommend that I use an existing API.  I'm doing this for
fun and maybe to come up with a simple pure python database driver.

Randall

В списке pgsql-general по дате отправления:

Предыдущее
От: Himanshu Baweja
Дата:
Сообщение: Relation between pgsql_tmp and work_mem
Следующее
От: John DeSoi
Дата:
Сообщение: Re: connecting to server process via sockets