Here is a different way using TELNET. It may be of some use to you.
Be sure to replace the three digit city code with your desired city code. Then clean up the resulting string and read as desired.
Code: Select all
; TELNET
; by Pantcho
; from PB Forum topic http://purebasic.myforums.net/viewtopic.php?t=4455&highlight=telnet
; Modified by TerryHough - November 11, 2004
Enumeration
#Window
#EdGadget
#StrGadget
EndEnumeration
;#CR = Chr(13)
;#LF = Chr(10)
#CRLF = Chr(13) + Chr(10)
;Variables
Row = 1
Col = 1
fore = 7
back = 0
;command.s = LCase(ProgramParameter()) ; For use with Command Tail
Global Command.s : Command.s = "rainmaker.wunderground.com" : Global Port.l : Port.l = 23
; The following are the defined TELNET commands from RFC854
SE.s = Chr(240) ; End of subnegotiation parameters
NOP.s = Chr(241) ; No operation
DM.s = Chr(242) ; The data stream portion of a Synch (DataMark)
; always accompanied by a TCP Urgent notification
BRK.s = Chr(243) ; NVT character BRK = Break
IP.s = Chr(244) ; Function IP = Interrupt Process
AO.s = Chr(245) ; Function AO = Abort output
AYT.s = Chr(246) ; Function AYT = Are You There?
EC.s = Chr(247) ; Function EC = Erase Character
EL.s = Chr(248) ; Function EL = Erase Line
GA.s = Chr(249) ; The Go Ahead signal
SB.s = Chr(250) ; Indicates the following is a subnegotiation
; of the indicated option
WILL.s = Chr(251) ; Indicates the desire to begin performing or
; confirms you are performing the indicated option
WONT.s = Chr(252) ; Indicates the refusal to perform or continue
; to perform the indicated option
DO.s = Chr(253) ; Requests that the other party perform or confirms
; that you are expecting the other party to perform
; the indicated option
DONT.S = Chr(254) ; Demands that the other party stop performing or
; or confirms that you are no longer expecting the
; other party to perform the indicated option
IAC.s = Chr(255) ; Data Byte 255
TermType.s = Chr(24)
TermTypeSB.s = SB + TermType + Chr(1) + IAC + SE
TermTypeInfo.s = IAC + SB +TermType + Chr(0) + "ANSI" + IAC + SE
*Buffer= AllocateMemory(5000)
B.s ;Read Byte Buffer
;- Begin program action
If InitKeyboard()
If OpenWindow(#Window,0,0,500,540,"TELNET",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
AddKeyboardShortcut(#Window, #PB_Shortcut_Escape, #PB_Shortcut_Escape)
AddKeyboardShortcut(#Window, #PB_Shortcut_Return, #PB_Shortcut_Return)
EditorGadget(#EdGadget ,10, 10,480,480)
StringGadget(#StrGadget,10,500,480, 25,"")
AddGadgetItem(#EdGadget,-1,"PureBasic Telnet Client")
AddGadgetItem(#EdGadget,-1,"-----------------------")
AddGadgetItem(#EdGadget,-1,"")
While WindowEvent() : Wend
If command.s = ""
AddGadgetItem(#EdGadget,-1,"")
AddGadgetItem(#EdGadget,-1,"Usage - Tel <Host>")
AddGadgetItem(#EdGadget,-1,"")
While WindowEvent() : Wend
Delay(3000)
EndIf
AddGadgetItem(#EdGadget,-1,"Connecting to - " + command + " ...")
While WindowEvent() : Wend
If InitNetwork()
ConnectionID = OpenNetworkConnection(command, Port)
If ConnectionID
AddGadgetItem(#EdGadget,-1,"Online with " + Command)
While WindowEvent() : Wend
; SendNetworkString(ConnectionID, Chr(13)) ; send Carriage Return
SendNetworkString(ConnectionID, Chr(13)) ; send Carriage Return
;-Main Loop
;-NetComm
Repeat
SendChk = NetworkClientEvent(ConnectionID)
Select SendChk
Case 2 ; Raw data has been received
RequestLength.l = ReceiveNetworkData(ConnectionID, *Buffer, 5000)
B.s = PeekS(*Buffer,RequestLength)
If Mid(B,1,3) = IAC
MessageRequester("Debug","Got an IAC " + Mid(B,1,3),0)
Gosub HandleOPT ; Process Telnet Protocol
Else
If FindString(B,"Press Return to continue",1)
SendNetworkString(ConnectionID, Chr(10)) ; send ^J
Else
B = ReplaceString(B,#LF$+#LF$,#LF$)
B = ReplaceString(B,#LF$+#CR$,#CR$)
AddGadgetItem(#EdGadget,-1, B)
While WindowEvent() : Wend
EndIf
EndIf
If FindString(B,"enter 3 letter forecast city code",1)
AddGadgetItem(#EdGadget,-1,"")
While WindowEvent() : Wend
; >>>> -------Send a 3 digit city code now. -----------------------------<<<<
SendNetworkString(ConnectionID, "GSO" + Chr(10)) ; send city code + ^J
; >>>> -------Replace with your desired 3 digit city code. --------------<<<<
ElseIf FindString(B,"Press Return for menu",1)
SetGadgetText(#StrGadget,"")
SetActiveGadget(#StrGadget)
EndIf
SetActiveGadget(#StrGadget)
Delay(20)
Case 1 ; A file has been received - Not used here
Case 0 ; Nothing has happened
EndSelect
SendMessage_(GadgetID(#EdGadget), #EM_SETSEL,-1,-1) ; scroll the Editor Gadget to last line
;SendMessage_(GadgetID(#EdGadget), #EM_SCROLLCARET, #False,#False) ; scroll the Editor Gadget to last line
Select WindowEvent()
Case #PB_Event_CloseWindow ; Window close box clicked
Quit = #True
Case #PB_Event_Menu
Select EventMenu() ; See which menu has been selected
Case #PB_Shortcut_Escape ; ESC key pressed
Quit = #True
Case #PB_Shortcut_Return ; Return key pressed
Command = UCase(GetGadgetText(#StrGadget))
SendNetworkString(ConnectionID, Command + #CRLF)
If Command = "X"
Quit = #True
EndIf
SetGadgetText(#StrGadget,"")
EndSelect ; End #PB_Event_Menu selection
EndSelect ; End WaitWindowEvent selection
Until quit = #True
If ConnectionID
CloseNetworkConnection(ConnectionID)
EndIf
Else
AddGadgetItem(#EdGadget,-1,"")
AddGadgetItem(#EdGadget,-1,"Could not connect to - " + command)
Delay(5000)
End
EndIf
Else
MessageRequester("ERROR","Couldn't initialize the network system",#MB_ICONERROR)
EndIf
Else
MessageRequester("ERROR","Couldn't create the TELNET window",#MB_ICONERROR)
EndIf
Else
MessageRequester("ERROR","Couldn't initialize keyboard handling",#MB_ICONERROR)
EndIf
End
;-HandleOPT
HandleOPT: ; Handle the TELNET Option commands
MessageRequester("Debug","Got here",0)
AddGadgetItem(#EdGadget,-1,"RCVD ")
; B.s=""
; RequestLength.l = ReceiveNetworkData(ConnectionID, *Buffer, 1000)
; B.s = PeekS(*Buffer)
If Mid(B,2,1) = WILL Or Mid(B,2,1) = WONT Or Mid(B,2,1) = DO Or Mid(B,2,1) = DONT
;RequestLength.l = ReceiveNetworkData(ConnectionID, *Buffer, 1000)
;More.s = PeekS(*Buffer)
;B=B+More
Select Mid(B,2,2)
Case DO + TermType
AddGadgetItem(#EdGadget,-1,"IAC DO TermType")
Command.s = IAC + WILL +TermType
SendNetworkString(ConnectionID,Command)
AddGadgetItem(#EdGadget,-1,"SENT IAC WILL TermType")
Delay(2000)
Default
If Mid(B,2,1) = DO ;Reply With WONT
AddGadgetItem(#EdGadget,-1,"IAC ["+Str(Asc(Mid(B,2,1)))+"]["+Str(Asc(Mid(B,3,1)))+"]")
Command.s = IAC + WONT + Mid(B,3,1)
SendNetworkString(ConnectionID,Command)
AddGadgetItem(#EdGadget,-1,"SENT IAC WONT "+Str(Asc(Mid(B,3,1))))
Delay(2000)
EndIf
EndSelect
Else
Select Mid(B,2,1)
Case SB ; negotiate sub options
While Mid(B,2,1) <> SE
RequestLength.l = ReceiveNetworkData(ConnectionID, *Buffer, 1000)
More.s = PeekS(*Buffer)
B = B + More
Wend
If B = TermTypeSB
AddGadgetItem(#EdGadget,-1,"REQUEST FOR TermType")
Command.s = TermTypeInfo
SendNetworkString(ConnectionID,Command)
AddGadgetItem(#EdGadget,-1,"SENT TermType INFORMATION")
Delay(2000)
Else
AddGadgetItem(#EdGadget,-1,"Unknown Suboption... Ignoring")
Delay(20)
EndIf
Default
AddGadgetItem(#EdGadget,-1,"Unknown Option...Ignoring")
Delay(20)
EndSelect
EndIf
Return