Re: Transmit Out-of-band data messages in TCP client/server pair

Adrian Phillips - Tandem User (tandem@typhoon.oslo.dnmi.no)
28 Apr 1994 06:19:26 GMT

Okay, off the top of my head (and a small look at the python manual
:-)

*WARNING* This is untested and also the python stuff may not be quite
right

from socket import * # Or import socket but makes more mess :-)
from SOCKET import * # If you want to use SO_OOBLINE
# Manual says socket options are in module SOCKET but if you're not
# on SGI or SUN, you have to make your own (see python/demo/scripts
# directory) - the script h2py, its ot perfect but it does most of
# the work

import ERRNO # You'll have to make this yourself with h2py

s = socket (AF_INET, SOCK_STREAM)
s.bind ('', 7654)
# Use this next if you want OOB stuff in same queue as ordinary data
# ie. don't use MSG_OOB, but you have touse SIOCATMARK ioctl
# to determine where OOB data is in normal stream (unless you
# flag it explicitly)
s.setsockopt (SOL_SOCKET, SO_OOBLINE)

max = 4096

# Just do this if you use setsockopt
s.recv (max, 0)

# Use this if you don't use the above setsockopt
try:
s.recv (max, MSG_OOB)
except error, err:
if err[0] = errno.EWOULDBLOCK:
# This means OOB data exists but hasn;t arrived yet !!
elif err[0] = errno.EINVAL:
# This means there is OOB stuff waiting
else:
raise socket.error

Perhaps one of the python experts would like to correct the python :-)

a-quick-hackly-yours, (-- is this allowed Tim ? :-)

Adrian

--
-------------------------------------------------------------------------
= Adrian Phillips at            | BUT any thoughts in this are purely    =
= The Norwegian Meteorological  | my own and have nothing to do with     =
= Institute   	    	        | this establishment, thankfully.        =
= Net: adrian.phillips@dnmi.no  | Phone: 47 22 96 32 09 Fax: 47 22 96 30 50