--- Passes if connect and initialize socket every time ---
* Connect failed 0 times
Time connect = 7
Time send = 9
recv ok = true
Recv[ 0] = 1642 y = 1642
Recv[ 1] = 384 y = 384
Time recv = 2016
Total recv 2028 append time = 2017
* Connect failed 0 times
Time connect = 7
Time send = 8
recv ok = true
Recv[ 0] = 3288 y = 3288
Time recv = 2019
Total recv 3289 append time = 2020
* Connect failed 0 times
Time connect = 8
Time send = 10
recv ok = true
Recv[ 0] = 861 y = 861
Time recv = 2029
Total recv 862 append time = 2030
--- Fails if try and reuse socket ---
*
Test_Send
* Connect failed 0 times
Time connect = 10
Time send = 12
recv ok = true
Recv[ 0] = 2026 y = 2026
Time recv = 2032
Total recv 2027 append time = 2033
*
Test_Send
Time send = 2
recv ok = true <-------- 2 recieve also fails ????
Time recv = 6
*
Test_Send
sent 0 of 836
status = 0
>>>>> Send Failed <<<<<
----------------------------------------------------------------------
Function Test_Send( host as string, obuf as object, ibuf as object )
? "Test_Send"
tcp = m.tcp
if tcp = invalid
tcp = TCP_Connect( host )
if tcp <> invalid
? "Time connect = " m.timer.TotalMilliseconds()
else
? "Connect failed for " host
Disp( "Failed to Connect to "+Chr(10)+host )
return invalid
end if
m.tcp = tcp
end if
tcp.setMessagePort( invalid )
tcp.notifyReadable( false )
z = obuf.Count()
obuf[z] = 0
x = tcp.send( obuf, 0, z )
if x <> z
? "sent " x " of " z
? "status = " tcp.status()
Disp( "Send Failed" )
return invalid
end if
? "Time send = " m.timer.TotalMilliseconds()
port = createobject( "roMessagePort" )
tcp.setMessagePort( port )
tcp.notifyReadable( true )
ok = tcp.eOK()
? "recv ok = " ok
while ok
ev = wait( 100, port )
if type(ev) = "roSocketEvent"
if ev.getSocketID() = tcp.getID()
if tcp.isReadable()
x = tcp.getCountRcvBuf()
if x = 0 exit while
e = ibuf.Count()
ibuf.Push( createobject( "roByteArray" ))
ibuf[e][x] = 0
y = tcp.receive( ibuf[e], 0, x )
? "Recv[" e "] = " x " y = " y
if y <> x
Disp( "Receive Failed" )
return invalid
end if
end if
end if
end if
end while
? "Time recv = " m.timer.TotalMilliseconds()
End Function
Function TCP_Connect( host as string ) as object
fail = 0
while 1
adrs = createobject( "roSocketAddress" )
adrs.setAddress( host )
tcp = CreateObject( "roStreamSocket" )
tcp.setSendToAddress( adrs )
tcp.connect()
if tcp.isConnected()
exit while
else
fail = fail + 1
end if
tcp.Close()
tcp = invalid
if fail = 100 exit while
if fail > 10 sleep(10)
end while
? "* Connect failed " fail " times"
return tcp
End Function
----------------------------------------------------------------------
function main()
HttpGet = "GET / HTTP/1.1" + chr(13) + chr(10) + chr(13) + chr(10)
socket = CreateObject("roStreamSocket")
server = CreateObject("roSocketAddress")
server.setAddress("www.roku.com:80")
socket.setSendToAddress(server)
' sync
socket.connect()
print "Test: sent"; socket.sendStr(HttpGet); " bytes"
' async
port = CreateObject("roMessagePort")
socket.setMessagePort(port)
socket.notifyReadable(true)
msg = wait(5 * 1000, port)
if type(msg)="roSocketEvent" and socket.isReadable()
input = socket.receiveStr(1000)
print "Test: received"; Len(input); " bytes" '; ", input:"; chr(10); input
end if
' sync
socket.setMessagePort(invalid)
print "Test: sent"; socket.sendStr(HttpGet); " bytes"
end function