[Patches] [ python-Patches-1522400 ] irda socket support

SourceForge.net noreply at sourceforge.net
Fri Jul 14 10:19:28 CEST 2006


Patches item #1522400, was opened at 2006-07-14 16:19
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1522400&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Core (C code)
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: ÇñÓ¢²¨ (qyb)
Assigned to: Nobody/Anonymous (nobody)
Summary: irda socket support

Initial Comment:
the patch implements IrDA socket's getsockaddrarg()
support under Linux and Win32 platform.

Now we can connect to IrDA device from a socket object
and build more flexible wireless application.

I have test it under Windows XP.

Simple test: connect a irda device

from socket import *
from struct import *
s = socket(AF_IRDA, SOCK_STREAM)
info = s.getsockopt(SOL_IRLMP, IRLMP_ENUMDEVICES, 1024)
list = info[4:]
list
addr = unpack('I', list[:4])[0]
s.connect((addr, "IrDA:IrCOMM"))
s.close()


Complex test: Get mobile phone's deviceinfo by OBEX
protocol

from struct import *
from socket import *

def obex_genheader_byte_stream(opcode, byte_stream):
    length = htons(3 + len(byte_stream))
    return chr(opcode) + pack('h', length) + byte_stream

def obex_genheader_unicode(opcode, unistr):
    unistr = unistr + '\x00\x00'
    length = htons(3 + len(unistr))
    return chr(opcode) + pack('h', length) + unistr

def obex_connect(sockobj, target):
    if (len(target)):
        header = obex_genheader_byte_stream(0x46, target)
    else:
        header = ''
    length = htons(7 + len(header))
    cmd = chr(0x80) + pack('h', length) + chr(0x10) +
chr(0) + pack('h', htons(1024)) + header
    sockobj.sendall(cmd)
    return True

def obex_get(sockobj, filename):
    header = obex_genheader_unicode(0x01, filename)
    length = htons(3 + len(header))
    cmd = chr(0x83) + pack('h', length) + header
    sockobj.sendall(cmd)
    return True

s = socket(AF_IRDA, SOCK_STREAM)
info = s.getsockopt(SOL_IRLMP, IRLMP_ENUMDEVICES, 1024)
list = info[4:]
addr = unpack('I', list[:4])[0]
s.connect((addr, "IrDA:OBEX"))
obex_connect(s, '')
response = s.recv(4096)
obex_get(s, "telecom/devinfo.txt".encode('utf-16be'))
response = s.recv(4096)
print response[6:]
s.close()

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1522400&group_id=5470


More information about the Patches mailing list