[Tutor] sockets

Ajaya Babu ajaya@ncoretech.com
Fri, 21 Sep 2001 02:25:33 +0530


Hi,

I've not understand this problem fully. I really confused what is going
wrong.But any way I presume....that you are using sockets as a pipe to send
info between two process. For this they are many ways.

One way of doing this is using client server model using TCP sockets. It
gives reliable flow of information between end points.

Simple way of doing this is take one port common in both process

make a server in one thread like this

from socket import *

HOST = ''          #this is correct server will accept any host...,
PORT = 21568
BUFSIZ = 1024

ServerSocket = socket(AF_INET, SOCK_STREAM)

ServerSocket.bind((HOST, PORT))  #it takes tuple...as input
ServerSocket.listen()

while 1:
    data = ServerSocket.recv(BUFSIZ)  #it is just a example
    print data
    ServerSocket.send(data)




and in another process make a client like this

from socket import *
HOST = 'localhost'
PORT = 21568
BUFSIZ = 1024

ClientSocket = socket(AF_INET, SOCK_STREAM)
ClientSocket.connect((HOST, PORT))


while 1:
    data = raw_input('>')
    ClientSocket.send(data)


Some precautions...,

1. First you make sure that server starts ...this ensures that smooth
establishment
   of connections between these two.

2. Add your program to above server and client..., other wise it looks like
it got hung...,

3. Implement some kind of protocl between these two process I mean how to
shutdown the connection...and close..., what I do is I send command from
client to server or server to client then I close this connections dipend on
my data...,



Hope this helps..., If you have any specific doubt feel free.

with regards,
Ajaya babu



-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
Ravikumar Devarajan
Sent: Wednesday, September 19, 2001 10:35 PM
To: tutor@python.org
Subject: [Tutor] sockets


hi all,
im trying to do the following in python
 i have 2 processes.i need them to communicate.and they will have to send
and receive stuff till i close the connection.somehow this doesnt seem to
work.im using sockets. and i want to know if theres any way by which i can
keep the connection open as long as i want.i wud really appreciate any help
in this regard.

thanks
Ravikumar



Make a difference, help support the relief efforts in the U.S.
http://clubs.lycos.com/live/events/september11.asp

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor