December 11, 2024, 09:45:53 PM

News:

IWBasic runs in Windows 11!


Server not returning data

Started by Allan, February 17, 2009, 12:50:59 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Allan

I am trying to get a NCS prog to work that I need.

Code below:-

It all appears to be working up till waiting for the data to return.

Message in bottom edit shows the GET Command was sent and it can be seen to fire on the Network Icon in the window Taskbar.

I am using an XP sp2  networked computer - connected via HUB to another XP SP2 which has the internet connection.

Can anyone see what I am missing please?

'TABDLG
AUTODEFINE "Off"

CONST STATIC_1 = 1
CONST STATIC_2 = 2
CONST EDIT_RCECDE = 3
CONST EDIT_RCENUM = 4
CONST STATIC_5 = 5
CONST EDIT_TIME = 6
CONST BUTTON_START = 7
CONST LISTVIEW_8 = 8
CONST BUTTON_CLOSE = 9
CONST EDIT_STATUS = 10
CONST EDIT_DATA = 11

GLOBAL string TodayDate
int datasocket=-1
int ncsStatus

string msgs
string WebSite, MeetUrl
istring buffer[30000]

DIALOG TabDlg
CREATEDIALOG TabDlg,0,0,676,419,0x80C80080,0,"Tab Data",&TabDlg_handler
CONTROL TabDlg,@STATIC,"Tab Race Code",23,20,80,17,0x5000010B,STATIC_1
CONTROL TabDlg,@STATIC,"Race Number",157,20,74,14,0x5000010B,STATIC_2
CONTROL TabDlg,@EDIT,"VR",107,17,36,20,0x50810000,EDIT_RCECDE
CONTROL TabDlg,@EDIT,"7",232,17,27,20,0x50812000,EDIT_RCENUM
CONTROL TabDlg,@STATIC,"Time (seconds)",362,20,79,16,0x5000010B,STATIC_5
CONTROL TabDlg,@EDIT,"0",443,17,34,20,0x50812000,EDIT_TIME
CONTROL TabDlg,@BUTTON,"Start",501,15,70,23,0x50010000,BUTTON_START
CONTROL TabDlg,@LISTVIEW,"",24,57,315,303,0x50000001,LISTVIEW_8
CONTROL TabDlg,@BUTTON,"X",615,6,31,25,0x50000000,BUTTON_CLOSE
CONTROL TabDlg,@EDIT,"Edit4",24,376,629,20,0x50800880,EDIT_STATUS
CONTROL TabDlg,@EDIT,"Edit5",359,59,300,303,0x50B00004,EDIT_DATA


'SHOWDIALOG TabDlg, parent
SHOWDIALOG TabDlg

WAITUNTIL ISWINDOWCLOSED(TabDlg)
'cleanup
IF datasocket > -1
NCSCloseSocket(datasocket)
ENDIF
NCSFree()
END

SUB TabDlg_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW TabDlg
/* Initialize any controls here */
WebSite = "www.tabonline.com.au"
'initialize the client server library
ncsStatus = NCSInit(1,0)
IF ncsStatus < 0
msgs = "Error initializing Client Server library - " + NCSGetErrorText()
SETCONTROLTEXT(TabDlg, EDIT_STATUS, msgs)
ELSE
'Attempt to connect to server
msgs = "Client Server Library initialized"
SETCONTROLTEXT(TabDlg, EDIT_STATUS, msgs)
ncsStatus = NCSConnectToServer(WebSite,80)
IF ncsStatus < 0
msgs = "Error connecting to server - " + NCSGetErrorText()
SETCONTROLTEXT(TabDlg, EDIT_STATUS, msgs)
ELSE
'Register a message to be sent when data is read to be retrieved
datasocket = ncsStatus
msgs = "Connected to server, Socket ="+str$(datasocket)
SETCONTROLTEXT(TabDlg, EDIT_STATUS, msgs)
ncsStatus=NCSOnDataMessage(TabDlg.hWnd, datasocket, 7000)
if ncsStatus < 0
msgs = "NCSOnDataMessage error - " + NCSGetErrorText()
SETCONTROLTEXT(TabDlg, EDIT_STATUS, msgs)
endif
ENDIF
ENDIF
CASE 7000
'data from server
ncsStatus = NCSReadData(datasocket,buffer,29999,1000)
IF ncsStatus > 0
msgs = "Received" + str$(ncsStatus) + " bytes"
SETCONTROLTEXT(TabDlg, EDIT_STATUS, msgs)
buffer[ncsStatus] = 0
SETCONTROLTEXT(TabDlg, EDIT_DATA, buffer)
'Arm the data message for further data.
ncsStatus=NCSOnDataMessage(TabDlg.hWnd, datasocket, 7000)
ELSEIF ncsStatus < 0
msgs = "ERROR :" + str$(ncsStatus)
SETCONTROLTEXT(TabDlg, EDIT_STATUS, msgs)
ENDIF
CASE @IDCLOSEWINDOW
CLOSEDIALOG TabDlg
CASE @IDCONTROL
SELECT @CONTROLID
CASE EDIT_RCECDE
/* respond to edit notifications here */
CASE EDIT_RCENUM
/* respond to edit notifications here */
CASE EDIT_TIME
/* respond to edit notifications here */
CASE BUTTON_START
IF @NOTIFYCODE = 0
/*button clicked*/
GetRaceData()
ENDIF
CASE LISTVIEW_8
/* respond to control notifications here */
CASE BUTTON_CLOSE
IF @NOTIFYCODE = 0
/*button clicked*/
CLOSEDIALOG TabDlg
ENDIF
CASE EDIT_STATUS
/* respond to edit notifications here */
CASE EDIT_DATA
/* respond to edit notifications here */
ENDSELECT
ENDSELECT
RETURN
ENDSUB


SUB GetRaceData
int success = 0

MeetUrl = ""
' obtain the Url for the race
success = GetWebUrls()

IF success = 1
IF datasocket > -1
'send server a command
msgs = "Sending GET command - " + MeetUrl
SETCONTROLTEXT(TabDlg, EDIT_STATUS, msgs)
string toSend = "GET / HTTP/1.1\nHost:" + MeetUrl + "\n\n"
NCSSendData(datasocket,toSend,len(toSend)+1)
ENDIF
ENDIF
ENDSUB

sub GetWebUrls(),int
int success = 0
string str1, str2, strtime

' get the RceCde for the TAB Meeting
str1 = GETCONTROLTEXT(TabDlg, EDIT_RCECDE)
IF LEN(str1) < 2
MESSAGEBOX (TabDlg,"A two-letter UniTAB Race Code Abbreviation (eg: VR) must be entered\n\ninto the Tab Race Code Edit Box","Input Error",@MB_ICONSTOP | @MB_OK)
RETURN success
ELSE
str1 = UCASE$(str1)
ENDIF

' get the Race Number for the Rce Cde meeting
str2 = GETCONTROLTEXT(TabDlg, EDIT_RCENUM)
IF LEN(str2) < 1
MESSAGEBOX (TabDlg,"A Race Number must be entered\n\ninto the Race Number Edit Box","Input Error",@MB_ICONSTOP | @MB_OK)
RETURN success
ENDIF

' get timer repeat value
strtime = GETCONTROLTEXT(TabDlg, EDIT_TIME)
IF LEN(strtime) < 1
MESSAGEBOX (TabDlg,"A Time Value in seconds must be entered\n\ninto the Time (seconds) Edit Box","Input Error",@MB_ICONSTOP | @MB_OK)
RETURN success
ENDIF

' todays date for testing
TodayDate = "2009/02/17/"
' create the string for the web address of the race
' http://www.tabonline.com.au/2009/02/17/VR06.html
MeetUrl = WebSite + "/"
MeetUrl += TodayDate
MeetUrl += str1
IF LEN(str2) < 2
MeetUrl += "0" + str2
ELSE
MeetUrl += str2
ENDIF
' add the .html
MeetUrl += ".html"

SETCONTROLTEXT(TabDlg, EDIT_STATUS, MeetUrl)
success = 1
RETURN success
ENDSUB


Ionic Wind Support Team

Couple of things:

string toSend = "GET / HTTP/1.1\nHost:" + MeetUrl + "\n\n"

You apparently copied from NCS simple.  The first "/" is the data you are trying to "GET". It should not be appended to the host.    NCS simple just gets the index page of the server.  So you are sending a mailformed http request, which the server is most likely ignoring. 

So change it to this:

string toSend = "GET "+MeetUrl+" HTTP/1.1\nHost:" + website + "\n\n"

And change MeetUrl to not include the website address:

MeetUrl = "/"
MeetUrl += TodayDate
MeetUrl += str1

I did that and it returned data.  What you do with that data is up to you.

Paul.

Ionic Wind Support Team

Allan

Paul

Thanks for the info. Yes I did use code from your example. I am no wise one in HTML or Networking so use your code to learn.

Have the program working fine with the changes.

Allan