-   Programming (
-   -   python s.send > c tcpServer (

donnied 01-22-2008 06:08 AM

python s.send > c tcpServer
I am trying to send data to a simple tcpServer ( from using the Python.

The connection is established but the tcpserver doesn't show any data being sent. It's waiting for something.
I tried s.send("7/r/n/") but I believe it wants an end of line / end of buffer statement, and that the connection should then be closed.

I tried s.close() but then it just froze up.

The code for the tcpclient (that I know) sends what's needed has :

send(sd, argv[i], strlen(argv[i]) + 1, 0)

but I'm not sure how to interpret it.

donnied 02-02-2008 06:26 PM

s.send( "9\0", 0) is what was needed to send a 9,
s.send( "3\0", 0) to send a 3, etc.

rubadub 02-02-2008 10:59 PM

where's your connect code?

donnied 02-09-2008 02:25 AM

Which connect code?

#!/usr/bin/env python

import socket


def togglebutton1_pressed(self, widget):
                s.send( "1\0", 0)
                print "7"


s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('', 1500))

I still have to manually edit the IP address to connect to. I would like in future to scan for/ or prompt the user for the IP address.

nc3b 02-09-2008 02:47 AM

Not really good at python, but I think you should be flushing the data..:-?

rubadub 02-09-2008 02:53 AM

if I remember correctly you need to provide 's', possibly two ways?

def togglebutton1_pressed(self, widget):
                global s
                s.send( "1\0", 0)
                print "7"


def togglebutton1_pressed(self, widget):
                self.s.send( "1\0", 0)
                print "7"

depending on how and where you declare s.

(p.s. I may be very wrong, lol, but I can't see rest of code!)

donnied 02-09-2008 02:59 AM

how shall I flush?
How do you mean 'flush the data'? Client side, I was relying on the built in garbage collection. Server side the program is a C echo server, do you think it needs some additional info?

nc3b 02-09-2008 03:06 AM

I don't know about python very well, but generally, to ensure that data is sent immediately, one must flush it. For instance, in C you would create a file stream from your socket and then you would write to that file. To make sure it sent it, you would call fflush. Again, I don't know if this is the case with your program. Another thing I suggest is trying to connect with telnet to your server. See what happens. If it doesn't work from there either then you know the problem is on the otherside. Cheers:)

donnied 02-09-2008 10:52 AM

The program was working fine. The second posting of mine was just to show how I fixed the problem.

Thank you.

All times are GMT -5. The time now is 08:29 AM.