473,385 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

another question about buffers

lo there all !

i finally got my script to receive info on a socket. but i need to
somehow set up a loop that will continue to listen for more info
comming across the same socket.

the way it works is, i log in with a login and password, it shoots back
an acknowlagement, then i send a request for data. every so often it
will send a packet of data that i need to record. i know how to receive
once, but i dont know how to go back to receive again.

the messages all start with "STX" and end with "ETX"

here is what i have so far. (it isn't working very well)

#set a socket to communicate with the server
serverhost = '10.10.10.4'
serverport = 9550

print 'connecting to server'
sockobj = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sockobj.connect((serverhost,serverport))
login = 'STXusernamepasswordETX'
sockobj.send(login)
login_ack = sockobj.recv(1028)
if login_ack:
print 'received login_ack'
else:
print 'login failure'

req = "STXsendreqETX"
sockobj.send(req) # send request for data stream

databack = sockobj.recv(1028)
if databack:
print 'caught a message %s bytes ' % len(databack)
else:
print 'fail to recieve data from server'

the output in the terminal runs fine until it fails to get the
databack, it prints out the "fail to receive from server" bit.

anything obvious that i am missing here?

thanks

Apr 21 '06 #1
3 1012
In article <11**********************@g10g2000cwb.googlegroups .com>,
ne*****@xit.net wrote:
databack = sockobj.recv(1028)
if databack:
print 'caught a message %s bytes ' % len(databack)
else:
print 'fail to recieve data from server'

the output in the terminal runs fine until it fails to get the
databack, it prints out the "fail to receive from server" bit.


Perhaps the string you are receiving back on the second recv is being
interpreted as False.
Apr 22 '06 #2
i think it may be,
i am just doing a while 1: loop to just wait for whatever comes in.
thanks

Apr 22 '06 #3
In article <11**********************@i39g2000cwa.googlegroups .com>,
ne*****@xit.net wrote:
i think it may be,


Moral: don't use arbitrary values as booleans.
Apr 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Skwerl | last post by:
Hi guys. I've written code to embed an ICC profile in a TIFF image, and I think my IO operations are slowing things down. It is taking about a second to embed each tag in 7-meg TIFF files. ...
2
by: DrBob | last post by:
gcc 3.3 on Mac OS X. I need to dynamically grow a buffer by concatinating raw binary data in chunks. How do I use 'new' to grow the buffer size as its contents grow? I know this can be done...
2
by: anna_cheng11 | last post by:
We do not have a DBA available, and this is a development environment, hence I was asked to do the work. I am not a DBA. I need some help to clarify my understanding of DB2 recovery and I am...
81
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there...
18
by: JG | last post by:
Does anyone know a standard (or supported on Linux, Mac, Win32) way to clear a read stream buffer (standard ANSI C file stream)? I would even settle for a platform specific way of doing it. ...
0
by: Sam Durai | last post by:
Hello, A particular select query took unusually long time to execute hence I took an app.snap to find out what happens internally and I found out that tablequeue buffers are overflowing on a...
5
by: Angus | last post by:
Hello I am doing this in a worker thread: char* szPartial = new char; if (szPartial) { lstrcpy(szPartial, szBuffer); PostMessage(m_thishWnd, WM_USER+1, 0, (LPARAM)szPartial); }
4
by: OhKyu Yoon | last post by:
Hi! I have a really long binary file that I want to read. The way I am doing it now is: for i in xrange(N): # N is about 10,000,000 time = struct.unpack('=HHHH', infile.read(8)) # do...
3
by: Michel Esber | last post by:
Hi all, Db2 v8 FP15 LUW . create table T (ID varchar (24), ABC timestamp) There is an index for (ID, ABC), allowing reverse Scans. My application needs to determine MIN and MAX(ABC) for a...
3
by: darren | last post by:
Hi there Im working on an assignment that has me store data in a buffer to be sent over the network. I'm ignorant about how C++ stores data in an array, and types in general. If i declare an...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.