Top > OOoBasic > Generic > Connecton

*接続 [#t3595b95]
TCP/IP や pipe に接続します。
HTTP Request を送信、データの受信を行えば GET や POST も行えます。2.0.4 では Connector サービスにバグあり(?)。

#code(ob){{
Sub Main
  sConnectTo = "socket,host=localhost,port=80"
  oConnector = CreateUnoService( _
    "com.sun.star.connection.Connector")
  oConnection = oConnector.connect(sConnectTo)
  
  oStreamListener = CreateUnoListener("XStream_", _
    "com.sun.star.io.XStreamListener")
  sCR = chr(13)
  sLF = chr(10)
  sRequest = "GET /HTTP/1.1" & sCR & sLF & sCR & sLF
  
  oConnection.write(String2Byte(sRequest))
  
  nBytes = Array()
  oConnection.read(nBytes,250)
  
  sStr = Byte2String(nBytes)
  
  msgbox sStr
  oConnection.close()
End Sub


Sub XStream_started()
End Sub
Sub XStream_closed()
End Sub
Sub XStream_terminated()
End Sub
Sub XStream_error( oEv )
End Sub
Sub XStream_disposing( oEv )
End Sub


Function String2Byte( sStr As String )
  nLen = Len(sStr)
  Dim nBytes(nLen -1) As Integer
  For i = 1 To nLen Step 1
    nChar = Asc(Mid(sStr,i,1))
    If nChar > 127 Then nChar = nChar - 256
    nBytes(i -1) = nChar
  Next
  String2Byte = nBytes
End Function


Function Byte2String( nBytes ) As String
  sStr = ""
  For i = 0 To UBound(nBytes) Step 1
    nByte = nBytes(i)
    If nByte < 0 Then nByte = nByte + 256
    sStr = sStr & chr(nByte)
  Next
  Byte2String = sStr
End Function
}}

Reload   New Lower page making Edit Freeze Diff Upload Copy Rename   Front page List of pages Search Recent changes Backup   Help   RSS of recent changes