[Tutor] Network programming

Johan Geldenhuys johan at accesstel.co.za
Thu Sep 9 10:14:50 CEST 2004


I still have trouble when I want to send data out as soon as it comes in
from one side.
My server listens and accepts the calls and then builds the client
connection to the destination. Please see if you can assist.

Thanks

Johan
####################################################

# we have an incoming socket connect
                    newConn, addr = self._serverSocket.accept()
                    self.log('Connection received from: %s:%s' % addr)
                                        
		                 #while connection is active on server:
		                 while 1:
                            #self._ne1_id = '1234'
                            #self._ne2_id = '1111'
                          
                            indata = newConn.recv(8192)
                            self.log('First Data received from LCT:' +
`indata`)
                          
                            if '\xff' in indata:
		                             continue
                             
		                          if '\x01' in indata:
		                             continue
			                       
	                           #Look for string of 1234 in indata:
                             if indata[0:4] == self._ne1_id:
                                self.log('indata 0:4 is:' +
`indata[0:4]`)
                                self.sock = socket(AF_INET, SOCK_STREAM)
			     
			                            #connect to this destination if the
string is 1234
			                            self.sock.connect((self._ne1_ip,
self._ne1_port)) # This is previously defined
                               self.log('Connection established to NE1:
%s:%i' % (self._ne1_ip, self._ne1_port))
                               outdata = self.sock.recv(8192)
                               #when connection to destination is up:
			                            while 1:
				                                   if indata:
				                                   self.sock.send(indata)
			                                    self.log('indata send to NE, line
106: ' + `indata`)
				       
				                                  # If break sequence is received
from server side, close the client connection
                                       if '\x11' in indata:
					                                     self.log('Break character
received')
			                                   		  break
                                       self.sock.close()
			                                    self.log('connection to NE1 now
closed')
                                    
				                                   if oudata:
				                                      newConn.send(outdata)
			  	                                    self.log('Data from NE:' +
`outdata`)
###########################################################			               

				       

 


On Tue, 2004-09-07 at 14:58, Kent Johnson wrote:

> We might be better able to help if you post your code.
> 
> Here is a list of HTTP proxy servers written in Python, you might find 
> something helpful there:
> http://xhaus.com/alan/python/proxies.html
> 
> Kent
> 
> At 02:19 PM 9/6/2004 +0200, Johan Geldenhuys wrote:
> >Hi,
> >
> >I am new to Python and would like to know more about network programming 
> >in particilar.
> >
> >I have a script that sets up a socket server and must wait for incoming 
> >connections. Once a call has been accepted, it must make another socket 
> >connection to a destination.
> >
> >Now, I want to let these two "talk" to each other. Once the server 
> >receives data it must be send out to the destination and when the 
> >destination has data, it must be send out to the connection that made the 
> >first call to the server.
> >
> >Does anybody have any examples or tips on how I can let this happen. My 
> >calls work for the first batch of data and then when new data is received, 
> >the calls break.
> >
> >Thanks
> >
> >--
> >        Johan Geldenhuys
> >Access Telecommunication Systems
> >  Mail to: johan at accesstel.co.za
> >--
> >This message has been scanned for viruses and
> >dangerous content by <http://www.azitech.co.za>Azitech, and is
> >believed to be clean.
> >_______________________________________________
> >Tutor maillist  -  Tutor at python.org
> >http://mail.python.org/mailman/listinfo/tutor

-- 
       Johan Geldenhuys
Access Telecommunication Systems
 Mail to: johan at accesstel.co.za

-- 
This message has been scanned for viruses and
dangerous content by Azitech, and is
believed to be clean.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040909/0a43af29/attachment-0001.htm


More information about the Tutor mailing list