[LEFT][FONT=Courier New][COLOR=#0000ff]Sub [/COLOR][/FONT][FONT=Courier New][COLOR=#010101]App_Start[/COLOR][/FONT]
[FONT=Courier New][COLOR=#010101] client.New1[/COLOR][/FONT]
[FONT=Courier New][COLOR=#010101] client.Connect("xxx.xxx.xxx.xxx",23) [/COLOR][/FONT][FONT=Courier New][/FONT]
[FONT=Courier New][/FONT][FONT=Courier New][COLOR=#0000ff]msgbox[/COLOR][/FONT][FONT=Courier New][COLOR=#010101]("Client connected.")[/COLOR][/FONT]
[FONT=Courier New][COLOR=#010101] client.Close[/COLOR][/FONT][/LEFT]
[FONT=Courier New][COLOR=#0000ff]End Sub
Sub Connect(IP)
'ErrorLabel(errConnect)
WaitCursor(true)
TextBox2.Text = "Connecting to " & IP
Dim client
client.New1
client.Connect(IP,23)
stream.New1(client.GetStream,true)
TextBox2.Text = "Connection established."
Return
End Sub
Sub Globals
Dim buffer(0) As byte
End Sub
Sub App_Start
bit.New1
AddTimer("Timer1")
Timer1.Interval = 500
End Sub
Sub Connect(IP)
'ErrorLabel(errConnect)
WaitCursor(true)
TextBox2.Text = "Connecting to " & IP
client.New1
client.Connect(IP,23)
stream.New1(client.GetStream,true)
TextBox2.Text = "Connection established."
timer1.Enabled = true
WaitCursor(false)
End Sub
Sub Timer1_Tick
If client.DataAvailable Then
Dim buffer(4096) As byte
count = stream.ReadBytes(buffer(),4096)
TextBox2.Text = bit.BytesToString(buffer(),0,count)
End If
End Sub
Sub Timer1_Tick
[COLOR="Red"] If client.DataAvailable Then[/COLOR] Dim buffer(4096) As byte
count = stream.ReadBytes(buffer(),4096)
TextBox2.Text = bit.BytesToString(buffer(),0,count)
End If
End Sub
It's strange. DataAvailable should return the correct value.
Sub asub
...
s = "a command against the server"
netwritebuffer() = bit.StringToBytes(s,0,StrLength(s))
stream.WriteBytes(netwritebuffer())
...
GetServerResponse()
if expected response then
...
do the next command
...
end if
no success
End Sub
...
Sub GetServerResponse
'If client.DataAvailable Then
Dim bufferbits(4096) As byte
count = stream.ReadBytes(bufferbits(),4096)
buf = bit.BytesToString(bufferbits(),0,count)
Return buf
' End If
End Sub
Sub MySub
...
send something to the server
GetNetworkResponse
make a decision depending on buf
...
End Sub
Sub GetNetworkResponse
Do Until client.DataAvailable = true
Sleep(300)
Loop
Dim bufferbits(4096) As byte
count = stream.ReadBytes(bufferbits(),4096)
buf = bit.BytesToString(bufferbits(),0,count)
Return buf
End Sub
Sub GetNetworkResponse
x=1
buf = ""
Do Until client.DataAvailable = true
Sleep(500)
x = x+1
If x > 50 Then
Return
End If
Loop
Dim bufferbits(4096) As byte
count = stream.ReadBytes(bufferbits(),4096)
buf = bit.BytesToString(bufferbits(),0,count)
Return buf
End Sub
x=1
buf = ""
Do While buf = ""
x = x+1
' If x > 20 Then
' Return
' End If
Dim bufferbits(4096) As byte
count = stream.ReadBytes(bufferbits(),4096)
buf = bit.BytesToString(bufferbits(),0,count)
Sleep(500)
Loop
Return buf
end sub
Sub GetNetworkResponse
x=1
buf = ""
Do Until client.DataAvailable = true OR (buf <> "")
Sleep(500)
x = x+1
If x > 50 Then
Return
End If
Loop
Dim bufferbits(4096) As byte
count = stream.ReadBytes(bufferbits(),4096)
buf = bit.BytesToString(bufferbits(),0,count)
Return buf
End Sub
Sub NetGetData(req)
msg ="An error occurred connecting to " & URL
ErrorLabel("err2")
Client.New1
Client.Connect(URL, Port)
Stream.New1(Client.GetStream,true)
msg = "GET /" & req & " HTTP/1.1" & Crlf
msg = msg & "Host: " & URL & Crlf
msg = msg & "Proxy-Connection: Keep-Alive" & Crlf
msg = msg & "Pragma: no-cache" & crlf
If Secure Then
p = StringToBase64(User & ":" & password)
msg = msg & "Authorization: Basic " & p & Crlf
End If
msg = msg & Crlf
WebReq() = Stream.StringToBytes(msg)
Stream.WriteBytes2(WebReq(),0,StrLength(msg))
Timer = 0
Do
Sleep(SleepMs)
Timer = Timer + SleepMs
If Timer >= Timeout Then
Return "A timeout occurred communicating with " & Device
End If
Loop Until Client.DataAvailable = true
count = Stream.ReadBytes(WebResp(),4096)
msg = Stream.BytesToString (WebResp(), 0, Count)
Client.Close
If SubString(msg, 13,2) = "OK" Then
msg = SubString(msg, 44, StrLength(msg)-44)
Else
msg = "Badly formatted data received from " & Device
End If
err2:
If ChkDebug.Checked Then
Msgbox(msg,"Message data received")
End If
Return msg
End Sub
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?