Top > OOoBasic > Generic > Connecton

接続 Edit

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

  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
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