Message50698
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() |
|
Date |
User |
Action |
Args |
2007-08-23 15:53:34 | admin | link | issue1522400 messages |
2007-08-23 15:53:34 | admin | create | |
|