LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 01-22-2008, 06:08 AM   #1
donnied
Member
 
Registered: Oct 2006
Distribution: Debian x64
Posts: 198

Rep: Reputation: 30
python s.send > c tcpServer


I am trying to send data to a simple tcpServer ( from pont.net/sockets) 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.
 
Old 02-02-2008, 06:26 PM   #2
donnied
Member
 
Registered: Oct 2006
Distribution: Debian x64
Posts: 198

Original Poster
Rep: Reputation: 30
s.send( "9\0", 0) is what was needed to send a 9,
s.send( "3\0", 0) to send a 3, etc.
 
Old 02-02-2008, 10:59 PM   #3
rubadub
Member
 
Registered: Jun 2004
Posts: 233

Rep: Reputation: 33
where's your connect code?
 
Old 02-09-2008, 02:25 AM   #4
donnied
Member
 
Registered: Oct 2006
Distribution: Debian x64
Posts: 198

Original Poster
Rep: Reputation: 30
Which connect code?

Code:
#!/usr/bin/env python

import socket

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

Code:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', 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.
 
Old 02-09-2008, 02:47 AM   #5
nc3b
Member
 
Registered: Aug 2005
Posts: 330

Rep: Reputation: 32
Not really good at python, but I think you should be flushing the data..:-?
 
Old 02-09-2008, 02:53 AM   #6
rubadub
Member
 
Registered: Jun 2004
Posts: 233

Rep: Reputation: 33
if I remember correctly you need to provide 's', possibly two ways?
Code:
def togglebutton1_pressed(self, widget):
                global s
                s.send( "1\0", 0)
                print "7"
or
Code:
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!)
 
Old 02-09-2008, 02:59 AM   #7
donnied
Member
 
Registered: Oct 2006
Distribution: Debian x64
Posts: 198

Original Poster
Rep: Reputation: 30
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?
 
Old 02-09-2008, 03:06 AM   #8
nc3b
Member
 
Registered: Aug 2005
Posts: 330

Rep: Reputation: 32
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
 
Old 02-09-2008, 10:52 AM   #9
donnied
Member
 
Registered: Oct 2006
Distribution: Debian x64
Posts: 198

Original Poster
Rep: Reputation: 30
The program was working fine. The second posting of mine was just to show how I fixed the problem.

Thank you.
 
  


Reply

Tags
basic, python, tcp


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
tcpserver: fatal: no IP address for -u?? namgayp Linux - Server 0 07-16-2007 04:02 AM
replace inetd with tcpserver? aus9 Linux - Security 1 05-02-2007 12:12 AM
qmail tcpserver question branden_burger Linux - Networking 0 08-19-2006 05:55 AM
tcpserver programe using sockets by C language abdobl Programming 1 12-20-2004 05:04 AM
Can't get my tcpserver up Red evil Linux - Newbie 0 11-24-2003 03:25 AM


All times are GMT -5. The time now is 01:13 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration