| 高倆位二進制數據 | 意義 | 
| 00 | 這個數據包的 | 
| 01 | 這個數據包的 | 
| 10 | |
| 11 | 
| 十六進制值 | 標識名稱 | 標識含義 | 
| 0x01 | name | 標記對象的名稱(通常是文件的文件名) | 
| 0xc3 | length | 以字節為單位計算的對象長度 | 
| 0x44 | time | 時間(以iso 8601規范為標準) | 
| 0x480x49 | bodyend of body | 標識一個對象數據塊的開始標識這是對象的最后一個數據塊 | 
| 0x80 | connect | 標識申請開始一個對象傳輸會話,并可以在這個數據包中告知紅外接收方一些必要的兼容性信息。 | 
| 0x81 | disconnect | 標識對象傳輸會話結束 | 
| 0x020x82 | putfinal_put | 發送對象的put動作(當標識為0x82時說明這是最后的一個put動作) | 
| 0xa0 | success | 說明接收端已成功收到put動作發送的所有數據(一般是在成功收到final_put標識的數據包后的反饋) | 
| 0x90 | continue | 說明接收端已收到put動作發送的數據,因為final_put還沒出現,所以要求發送端繼續發送數據。 | 
| 字節0 | 字節1,2 | 字節三以后的數據 | 
| 操作碼 | 整個通信數據包的長度 | 通訊的數據 | 
| 字節0 | 字節1、2 | 字節3 | 字節4 | 字節5、6 | 字節7 | 
| connect操作碼(0x80) | connect數據包的總長度 | obex協議的版本(目前為1.0,16進制表示為0x10) | 保留未用,設為0 | 最大可處理的obex包長度 | 其它的數據包(可選) | 
| 字節0 | 字節1、2 | 字節3 | 字節4 | 字節5、6 | 字節7 | 
| 響應的操作碼 | 響應數據包的總長度 | obex協議的版本(目前為1.0,16進制表示為0x10) | 保留未用,設為0 | 最大可處理的obex包長度 | 其它的數據包(可選) | 
| 字節0 | 字節1,2 | 字節三以后的數據 | 
| put操作碼(0x02)final_put操作碼(0x82) | 整個通信數據包的長度 | 通訊的數據(由其它的例如name/body等數據包構成) | 
| 字節0 | 字節1,2 | 字節三以后的數據 | 
| 響應操作碼典型的有兩個值:success操作碼(0xa0)continue操作碼(0x90 ) | 整個通信數據包的長度 | 通訊的數據(由其它的例如name/body等數據包構成) | 
| 字節0 | 字節1,2 | 字節三以后的數據 | 
| disconnect操作碼 | 整個通信數據包的長度 | 可選的通訊的數據(由其它的數據包構成) | 
| 字節0 | 字節1,2 | 字節三以后的數據 | 
| success操作碼(0xa0)服務不可用操作碼(0xd3) | 整個通信數據包的長度 | 可選的通訊的數據(由其它的數據包構成) | 
| irdaclient | 提供連接信息,并創建客戶端連接對象,用以打開和關閉與服務器的連接。 | 
| irdadeviceinfo | 提供客戶端在發現查詢過程中獲取的有關可用服務器和端口的信息。 | 
| irdalistener | 將套接字置于偵聽狀態,以監視來自指定服務或網絡地址的連接。 | 
| dim taobjirdadeviceinfo() as sockets.irdadeviceinfo dim tobjirdaclient as new sockets.irdaclient '開始檢索附近的紅外設備并加入到列表中,最多只搜索7個設備 taobjirdadeviceinfo = tobjirdaclient.discoverdevices(7) | 
| dim tobjirdaclient as new sockets.irdaclient 'ni_objirdadeviceinfo是上文介紹的irdadeviceinfo對象,以下語句的含義就是連接到'deviceid指定的紅外設備上,這個設備提供obex服務。 dim tobjirdaendpoint as new irdaendpoint(ni_objirdadeviceinfo.deviceid, "obex") try tobjirdaclient.connect(tobjirdaendpoint) catch ex as exception messagebox.show("irda socket connect 狀態失敗") end try | 
| imports system.net imports system.net.sockets public class clsirdaobexoperator 'obex常數 public const cobex_version as byte = &h10 public const cobex_connectflags as byte = &h0 public const cobex_connect as byte = &h80 public const cobex_disconnect as byte = &h81 public const cobex_put as byte = &h2 public const cobex_name as byte = &h1 public const cobex_put_final as byte = &h82 public const cobex_length as byte = &hc3 public const cobex_body as byte = &h48 public const cobex_end_of_body as byte = &h49 public const cobex_continue as byte = &h90 public const cobex_success as byte = &ha0 '向外界公布可直接修改的變量 public m_i32obexmaxsendbufferlen as int32 = 255 public m_i32obexmaxreceivebufferlen as int32 = 1024 public m_i32obexmaxpacketsize as int16 = &h808 '將一個16位整數轉為2個字節的數組,并存入參數中指定索引開始的字節數組處(低位字在低字節,高位字在高字節) private function fnint16tobytearray(byval ni_i16convert as int16, byref ni_abytdest() as byte, byval ni_i32startindex as int32) as boolean ni_abytdest(ni_i32startindex) = ni_i16convert and &hff ni_abytdest(ni_i32startindex + 1) = ni_i16convert >> 8 end function '將一個16位整數轉為2個字節的數組,并存入參數中指定索引開始的字節數組處 private function fnint16tobytearraylowbytetohightposition(byval ni_i16convert as int16, byref ni_abytdest() as byte, byval ni_i32startindex as int32) as boolean ni_abytdest(ni_i32startindex + 1) = ni_i16convert and &hff ni_abytdest(ni_i32startindex) = ni_i16convert >> 8 end function '將一個32位整數轉為4個字節的數組,并存入參數中指定索引開始的字節數組處 private function fnint32tobytearraylowbytetohightposition(byval ni_i32convert as int16, byref ni_abytdest() as byte, byval ni_i32startindex as int32) as boolean dim ti32tempa as int32 = ni_i32convert ni_abytdest(ni_i32startindex + 3) = ni_i32convert and &hff ni_abytdest(ni_i32startindex + 2) = (ni_i32convert and &hff00) >> 8 ni_abytdest(ni_i32startindex + 1) = (ni_i32convert and &hff0000) >> 16 ni_abytdest(ni_i32startindex) = (ti32tempa and &hff000000) >> 24 end function '將本設備中指定的文件傳到指定的設備中去 public function fnsendfiletoirdadevice(byval ni_objirdadeviceinfo as irdadeviceinfo, _ byval ni_strfilepath as string) as boolean 'ni_objirdadeviceinfo:指定紅外設備的irdainfo結構 'ni_strfilepath:要傳輸的文件路徑 '返回值:成功返回true dim tobjirdaclient as new sockets.irdaclient dim tobjirdaendpoint as new irdaendpoint(ni_objirdadeviceinfo.deviceid, "obex") dim tabytsendbuffer(m_i32obexmaxsendbufferlen * 2) as byte dim tabytreceivebuffer(m_i32obexmaxreceivebufferlen) as byte dim tblntemp as boolean dim ti32tempa as int32, ti32tempb as int32, tietempc as int32 dim tbyttempa as byte dim ti32loopa as int32 dim tobjbinaryreader as io.binaryreader dim tobjfilestream as io.filestream dim tabyttempa() as byte, tabyttempb() as byte, tabyttempc() as byte, tabyttempd() as byte dim tabyttempe() as byte dim tobjobex_headers as new clsobexheaders dim ti32sendpackagespare as int32 '保存最大發送包數組-當前數據后的剩余空間 dim tobjfileinfo as io.fileinfo tobjfileinfo = new io.fileinfo(ni_strfilepath) try try tobjirdaclient.connect(tobjirdaendpoint) catch ex as exception messagebox.show("irda socket connect 狀態失敗") return false end try '創建一個最簡單的連接信息 tabyttempa = tobjobex_headers.fncreateconnectheaderrequest(, , , m_i32obexmaxpacketsize) try tobjirdaclient.getstream.write(tabyttempa, 0, tabyttempa.length) tobjirdaclient.getstream.flush() catch ex as exception messagebox.show("obex_connect信息發送失敗") application.doevents() return false end try if tobjirdaclient.getstream.canread = true then try tobjirdaclient.getstream.read(tabytreceivebuffer, 0, 7) catch ex as exception messagebox.show("接收obex_connect響應消息失敗") return false end try if tabytreceivebuffer(0) <> cobex_success then messagebox.show("obex_connect沒接收到相應的響應") return false end if end if '發送put包 'name包 tabyttempa = tobjobex_headers.fncreatenameheader(io.path.getfilename(ni_strfilepath)) ti32tempa = tabyttempa.length 'lenght包 tabyttempb = tobjobex_headers.fncreatelengthheader(tobjfileinfo.length) ti32tempb = tabyttempb.length '時間 tabyttempc = tobjobex_headers.fncreatetimeheaderiso(now) redim preserve tabyttempa(tabyttempa.length + tabyttempb.length + tabyttempc.length) tabyttempb.copyto(tabyttempa, ti32tempa) tabyttempc.copyto(tabyttempa, ti32tempa + ti32tempb) tabyttempa = tobjobex_headers.fncreateputheader(tabyttempa) '將名稱、時間、文件長度等基本信息先發出去 try tobjirdaclient.getstream.write(tabyttempa, 0, tabyttempa.length) catch ex as exception return false end try try tobjirdaclient.getstream.read(tabytreceivebuffer, 0, tabytreceivebuffer.length) catch ex as exception '接收服務器端響應時失敗 tobjirdaclient.getstream.close() tobjirdaclient.close() return false end try if tabytreceivebuffer(0) <> cobex_success and tabytreceivebuffer(0) <> cobex_continue then '沒有收到服務器的對應的響應信息 tobjirdaclient.getstream.close() tobjirdaclient.close() return false end if '開始正式發送文件的數據 try tobjfilestream = io.file.open(ni_strfilepath, io.filemode.open, io.fileaccess.read) tobjbinaryreader = new io.binaryreader(tobjfilestream) catch ex as exception messagebox.show("打開文件時出現錯誤") tobjirdaclient.getstream.close() tobjirdaclient.close() return false end try '讀出文件的數據放到body中,總長度必須少于最大發送長度-put標志的3字節-body標志的3字節 '最多可發送的文件信息長度 ti32sendpackagespare = m_i32obexmaxsendbufferlen - 6 '循環讀取文件的內容,并發送到服務方 for ti32loopa = 1 to math.ceiling(tobjfileinfo.length / ti32sendpackagespare) try tabyttempa = tobjbinaryreader.readbytes(ti32sendpackagespare) catch ex as exception tobjirdaclient.getstream.close() tobjirdaclient.close() return false end try '構建合適的put包并發送 tabyttempb = tobjobex_headers.fncreatebodyheader(tabyttempa) 'body標志 tabyttempa = tobjobex_headers.fncreateputheader(tabyttempb) '開始發送 try tobjirdaclient.getstream.write(tabyttempa, 0, tabyttempa.length) tobjirdaclient.getstream.flush() catch ex as exception tobjirdaclient.getstream.close() tobjirdaclient.close() return false end try try tobjirdaclient.getstream.read(tabytreceivebuffer, 0, tabytreceivebuffer.length) catch ex as exception '接收服務器端響應時失敗 tobjirdaclient.getstream.close() tobjirdaclient.close() return false end try if tabytreceivebuffer(0) <> cobex_success and tabytreceivebuffer(0) <> cobex_continue then '沒有收到服務器的對應的響應信息 tobjirdaclient.getstream.close() tobjirdaclient.close() return false end if next '關閉文件 tobjbinaryreader.close() tobjfilestream.close() if ti32tempa then end if '文件數據已全部發送完畢,發送結束的final_put 包 'endbody包 tabyttempa = tobjobex_headers.fncreateendofbodyheader(nothing) 'putfinal tabyttempa = tobjobex_headers.fncreateput_finalheaderresponse(tabyttempa) try tobjirdaclient.getstream.write(tabyttempa, 0, tabyttempa.length) tobjirdaclient.getstream.flush() catch ex as exception tobjirdaclient.getstream.close() tobjirdaclient.close() return false end try try tobjirdaclient.getstream.read(tabytreceivebuffer, 0, tabytreceivebuffer.length) catch ex as exception tobjirdaclient.getstream.close() tobjirdaclient.close() return false end try if tabytreceivebuffer(0) <> cobex_success then '沒有收到服務器的對應的響應信息 tobjirdaclient.getstream.close() tobjirdaclient.close() return false end if '發送disconnect包 tabyttempa = tobjobex_headers.fncreatedisconnectheaderrequest() try tobjirdaclient.getstream.write(tabyttempa, 0, tabyttempa.length) tobjirdaclient.getstream.flush() catch ex as exception tobjirdaclient.getstream.close() tobjirdaclient.close() return false end try tobjirdaclient.close() catch ex as exception messagebox.show("過程發生不明錯誤") return false end try '代碼能來到這兒就是正常完成任務了 msgbox("紅外操作成功") return true end function end class clsobexheaders.vb文件的代碼: public class clsobexheaders #region "obex常數" public const cobex_version as byte = &h10 public const cobex_connectflags as byte = &h0 public const cobex_connect as byte = &h80 public const cobex_disconnect as byte = &h81 public const cobex_put as byte = &h2 public const cobex_name as byte = &h1 public const cobex_put_final as byte = &h82 public const cobex_length as byte = &hc3 public const cobex_body as byte = &h48 public const cobex_end_of_body as byte = &h49 public const cobex_time_iso as byte = &h44 public const cobex_continue as byte = &h90 public const cobex_success as byte = &ha0 #end region #region "類內私有函數" '將一個16位整數轉為2個字節的數組,并存入參數中指定索引開始的字節數組處 private sub sbint16tobytearraylowbytetohightposition(byval ni_i16convert as int16, byref ni_abytdest() as byte, byval ni_i32startindex as int32) ni_abytdest(ni_i32startindex + 1) = ni_i16convert and &hff ni_abytdest(ni_i32startindex) = ni_i16convert >> 8 end sub ''將一個16位整數轉為2個字節的數組,高位字放入高字節,并存入參數中指定索引開始的字節數組處 'private sub sbint16tobytearrayhightbytetohightposition(byval ni_i16convert as int16, byref ni_abytdest() as byte, byval ni_i32startindex as int32) ' ni_abytdest(ni_i32startindex) = ni_i16convert and &hff ' ni_abytdest(ni_i32startindex + 1) = ni_i16convert >> 8 'end sub '將一個32位整數轉為4個字節的數組,并存入參數中指定索引開始的字節數組處 private sub sbint32tobytearraylowbytetohightposition(byval ni_i32convert as int16, byref ni_abytdest() as byte, byval ni_i32startindex as int32) dim ti32tempa as int32 = ni_i32convert ni_abytdest(ni_i32startindex + 3) = ni_i32convert and &hff ni_abytdest(ni_i32startindex + 2) = (ni_i32convert and &hff00) >> 8 ni_abytdest(ni_i32startindex + 1) = (ni_i32convert and &hff0000) >> 16 ni_abytdest(ni_i32startindex) = (ti32tempa and &hff000000) >> 24 end sub #end region '創建一個新的connectheader客戶端請求信息 public function fncreateconnectheaderrequest(optional byval ni_abytotherheaders as byte() = nothing, _ optional byval ni_bytobex_version as byte = cobex_version, _ optional byval ni_bytflags as byte = cobex_connectflags, _ optional byval ni_i16maxpacketlength as int16 = 255) as byte() dim tabytfuncreturn() as byte if not (ni_abytotherheaders is nothing) then redim tabytfuncreturn(7 + ni_abytotherheaders.length - 1) else redim tabytfuncreturn(6) end if tabytfuncreturn(0) = cobex_connect tabytfuncreturn(3) = ni_bytobex_version tabytfuncreturn(4) = ni_bytflags sbint16tobytearraylowbytetohightposition(ni_i16maxpacketlength, tabytfuncreturn, 5) if ni_abytotherheaders is nothing then '沒有其它的頭信息了 '加入connect包的長度 call sbint16tobytearraylowbytetohightposition(7, tabytfuncreturn, 1) else '還有其它頭信息 ni_abytotherheaders.copyto(tabytfuncreturn, 7) call sbint16tobytearraylowbytetohightposition(ni_abytotherheaders.length + 7, tabytfuncreturn, 1) end if return tabytfuncreturn end function '創建一個新的connectheader的服務器端響應信息數據 public function fncreateconnectheaderresponse(optional byval ni_abytotherheaders as byte() = nothing, _ optional byval ni_bytobex_version as byte = cobex_version, _ optional byval ni_bytflags as byte = cobex_connectflags, _ optional byval ni_i16maxpacketlength as int16 = 255) as byte() dim tabytfuncreturn() as byte if not (ni_abytotherheaders is nothing) then redim tabytfuncreturn(7 + ni_abytotherheaders.length - 1) else redim tabytfuncreturn(6) end if tabytfuncreturn(0) = cobex_success tabytfuncreturn(3) = ni_bytobex_version tabytfuncreturn(4) = ni_bytflags sbint16tobytearraylowbytetohightposition(ni_i16maxpacketlength, tabytfuncreturn, 5) if ni_abytotherheaders is nothing then '沒有其它的頭信息了 '加入connect包的長度 call sbint16tobytearraylowbytetohightposition(7, tabytfuncreturn, 1) else '還有其它頭信息 ni_abytotherheaders.copyto(tabytfuncreturn, 7) call sbint16tobytearraylowbytetohightposition(ni_abytotherheaders.length + 7, tabytfuncreturn, 1) end if return tabytfuncreturn end function '創建一個新的disconnectheader客戶請求信息 public function fncreatedisconnectheaderrequest(optional byval ni_abytotherheaders as byte() = nothing) as byte() dim tabytfuncreturn() as byte if not (ni_abytotherheaders is nothing) then '有其它的數據包要附在后面 redim tabytfuncreturn(3 + ni_abytotherheaders.length - 1) else redim tabytfuncreturn(2) end if tabytfuncreturn(0) = cobex_disconnect if ni_abytotherheaders is nothing then '沒有其它的頭信息了 '加入包的長度 call sbint16tobytearraylowbytetohightposition(3, tabytfuncreturn, 1) else '還有其它頭信息 ni_abytotherheaders.copyto(tabytfuncreturn, 3) call sbint16tobytearraylowbytetohightposition(ni_abytotherheaders.length + 3, tabytfuncreturn, 1) end if return tabytfuncreturn end function '創建一個新的continueheader信息 public function fncreatecontinueheaderresponse(optional byval ni_abytotherheaders as byte() = nothing) as byte() dim tabytfuncreturn() as byte if not (ni_abytotherheaders is nothing) then '有其它的數據包要附在后面 redim tabytfuncreturn(3 + ni_abytotherheaders.length - 1) else redim tabytfuncreturn(2) end if tabytfuncreturn(0) = cobex_continue if ni_abytotherheaders is nothing then '沒有其它的頭信息了 '加入包的長度 call sbint16tobytearraylowbytetohightposition(3, tabytfuncreturn, 1) else '還有其它頭信息 ni_abytotherheaders.copyto(tabytfuncreturn, 3) call sbint16tobytearraylowbytetohightposition(ni_abytotherheaders.length + 3, tabytfuncreturn, 1) end if return tabytfuncreturn end function '創建一個新的successheader信息 public function fncreatesuccessheaderresponse(optional byval ni_abytotherheaders as byte() = nothing) as byte() dim tabytfuncreturn() as byte if not (ni_abytotherheaders is nothing) then '有其它的數據包要附在后面 redim tabytfuncreturn(3 + ni_abytotherheaders.length - 1) else redim tabytfuncreturn(2) end if tabytfuncreturn(0) = cobex_success if ni_abytotherheaders is nothing then '沒有其它的頭信息了 '加入包的長度 call sbint16tobytearraylowbytetohightposition(3, tabytfuncreturn, 1) else '還有其它頭信息 ni_abytotherheaders.copyto(tabytfuncreturn, 3) call sbint16tobytearraylowbytetohightposition(ni_abytotherheaders.length + 3, tabytfuncreturn, 1) end if return tabytfuncreturn end function '創建一個新的timeheader信息 public function fncreatetimeheaderiso(byval ni_dtmdate as date, optional byval ni_abytotherheaders as byte() = nothing) as byte() dim tabytfuncreturn() as byte dim tstrdate as string dim tabyttempa() as byte 'tstrdate = ni_dtmdate.year & "." & ni_dtmdate.month & "." & ni_dtmdate.day & "t" & _ ' ni_dtmdate.hour & ":" & ni_dtmdate.minute & ":" & ni_dtmdate.second & "z" & controlchars.nullchar tstrdate = string.format("{0:yyyy/mm/dd/thh:mm:ss/z}", ni_dtmdate) & controlchars.nullchar tabyttempa = text.encoding.bigendianunicode.getbytes(tstrdate) if not (ni_abytotherheaders is nothing) then '有其它的數據包要附在后面 redim tabytfuncreturn(3 + tabyttempa.length + ni_abytotherheaders.length - 1) else redim tabytfuncreturn(2 + tabyttempa.length) end if tabytfuncreturn(0) = cobex_time_iso tabyttempa.copyto(tabytfuncreturn, 3) '將時間字節串放入返回數組中 if ni_abytotherheaders is nothing then '沒有其它的頭信息了 '加入包的長度 call sbint16tobytearraylowbytetohightposition(3 + tabyttempa.length, tabytfuncreturn, 1) else '還有其它頭信息 ni_abytotherheaders.copyto(tabytfuncreturn, 3) call sbint16tobytearraylowbytetohightposition(ni_abytotherheaders.length + 3 + tabyttempa.length, tabytfuncreturn, 1) end if return tabytfuncreturn end function '創建一個新的bodyheader信息 public function fncreatebodyheader(byval ni_abytbodycontent() as byte, optional byval ni_abytotherheaders as byte() = nothing) as byte() dim tabytfuncreturn() as byte dim tabyttempa as byte dim ti32bodycontentlength as int32 = 0 '定義合適大小的數組以容納bodyheader的內容 if not (ni_abytbodycontent is nothing) then '有body的內容 if not (ni_abytotherheaders is nothing) then '有其它的數據包要附在后面 redim tabytfuncreturn(3 + ni_abytbodycontent.length + ni_abytotherheaders.length - 1) ni_abytbodycontent.copyto(tabytfuncreturn, 3) ni_abytotherheaders.copyto(tabytfuncreturn, ni_abytbodycontent.length + 3) else redim tabytfuncreturn(2 + ni_abytbodycontent.length) ni_abytbodycontent.copyto(tabytfuncreturn, 3) end if else '沒有body的內容 if not (ni_abytotherheaders is nothing) then '有其它的數據包要附在后面 redim tabytfuncreturn(3 + ni_abytotherheaders.length - 1) ni_abytotherheaders.copyto(tabytfuncreturn, 3) else redim tabytfuncreturn(2) end if end if tabytfuncreturn(0) = cobex_body '加入包的長度 call sbint16tobytearraylowbytetohightposition(tabytfuncreturn.length, tabytfuncreturn, 1) return tabytfuncreturn end function '創建一個新的endofbodyheader信息 public function fncreateendofbodyheader(byval ni_abytbodycontent() as byte, optional byval ni_abytotherheaders as byte() = nothing) as byte() dim tabytfuncreturn() as byte dim tabyttempa as byte dim ti32bodycontentlength as int32 = 0 if not (ni_abytbodycontent is nothing) then if not (ni_abytotherheaders is nothing) then '有其它的數據包要附在后面 redim tabytfuncreturn(3 + ni_abytbodycontent.length + ni_abytotherheaders.length - 1) ni_abytbodycontent.copyto(tabytfuncreturn, 3) ni_abytotherheaders.copyto(tabytfuncreturn, 3 + ni_abytbodycontent.length) else redim tabytfuncreturn(2 + ni_abytbodycontent.length) ni_abytbodycontent.copyto(tabytfuncreturn, 3) end if else '沒有body內容 if not (ni_abytotherheaders is nothing) then '有其它的數據包要附在后面 redim tabytfuncreturn(3 + ni_abytotherheaders.length - 1) ni_abytotherheaders.copyto(tabytfuncreturn, 3) else redim tabytfuncreturn(2) end if end if '加入包的長度 call sbint16tobytearraylowbytetohightposition(tabytfuncreturn.length, tabytfuncreturn, 1) tabytfuncreturn(0) = cobex_end_of_body return tabytfuncreturn end function '創建一個新的lengthheader信息 public function fncreatelengthheader(byval ni_i32length as int32) as byte() dim tabytfuncreturn() as byte redim tabytfuncreturn(4) tabytfuncreturn(0) = cobex_length '加入包的內容 call sbint32tobytearraylowbytetohightposition(ni_i32length, tabytfuncreturn, 1) return tabytfuncreturn end function '創建一個新的nameheader信息 public function fncreatenameheader(byval ni_strname as string, optional byval ni_abytotherheaders as byte() = nothing) as byte() dim tabytfuncreturn() as byte dim tabyttempa() as byte dim ti32bodycontentlength as int32 = 0 tabyttempa = text.encoding.bigendianunicode.getbytes(ni_strname & controlchars.nullchar) if ni_strname <> "" then if not (ni_abytotherheaders is nothing) then '有其它的數據包要附在后面 redim tabytfuncreturn(3 + tabyttempa.length + ni_abytotherheaders.length - 1) else '沒有其它數據包附后 redim tabytfuncreturn(2 + tabyttempa.length) end if else if not (ni_abytotherheaders is nothing) then '有其它的數據包要附在后面 redim tabytfuncreturn(3 + ni_abytotherheaders.length - 1) else redim tabytfuncreturn(2) end if end if tabytfuncreturn(0) = cobex_name if ni_strname <> "" then if ni_abytotherheaders is nothing then '沒有其它的頭信息了 '加入包的長度 call sbint16tobytearraylowbytetohightposition(3 + tabyttempa.length, tabytfuncreturn, 1) else '還有其它頭信息 ni_abytotherheaders.copyto(tabytfuncreturn, 3) call sbint16tobytearraylowbytetohightposition(ni_abytotherheaders.length + tabyttempa.length + 3, tabytfuncreturn, 1) end if tabyttempa.copyto(tabytfuncreturn, 3) else '沒有實際的body數據 if ni_abytotherheaders is nothing then '沒有其它的頭信息了 '加入包的長度 call sbint16tobytearraylowbytetohightposition(3, tabytfuncreturn, 1) else '還有其它頭信息 ni_abytotherheaders.copyto(tabytfuncreturn, 3) call sbint16tobytearraylowbytetohightposition(ni_abytotherheaders.length + 3, tabytfuncreturn, 1) end if end if return tabytfuncreturn end function '創建一個新的putheader信息 public function fncreateputheader(optional byval ni_abytotherheaders as byte() = nothing) as byte() dim tabytfuncreturn() as byte if not (ni_abytotherheaders is nothing) then '有其它的數據包要附在后面 redim tabytfuncreturn(3 + ni_abytotherheaders.length - 1) else redim tabytfuncreturn(2) end if tabytfuncreturn(0) = cobex_put if ni_abytotherheaders is nothing then '沒有其它的頭信息了 '加入包的長度 call sbint16tobytearraylowbytetohightposition(3, tabytfuncreturn, 1) else '還有其它頭信息 ni_abytotherheaders.copyto(tabytfuncreturn, 3) call sbint16tobytearraylowbytetohightposition(ni_abytotherheaders.length + 3, tabytfuncreturn, 1) end if return tabytfuncreturn end function '創建一個新的putheader信息 public function fncreateput_finalheaderresponse(optional byval ni_abytotherheaders as byte() = nothing) as byte() dim tabytfuncreturn() as byte if not (ni_abytotherheaders is nothing) then '有其它的數據包要附在后面 redim tabytfuncreturn(3 + ni_abytotherheaders.length - 1) else redim tabytfuncreturn(2) end if tabytfuncreturn(0) = cobex_put_final if ni_abytotherheaders is nothing then '沒有其它的頭信息了 '加入包的長度 call sbint16tobytearraylowbytetohightposition(3, tabytfuncreturn, 1) else '還有其它頭信息 ni_abytotherheaders.copyto(tabytfuncreturn, 3) call sbint16tobytearraylowbytetohightposition(ni_abytotherheaders.length + 3, tabytfuncreturn, 1) end if return tabytfuncreturn end function end class | 
新聞熱點
疑難解答
圖片精選