Skip to Content
It is currently June 27th, 2019, 6:16 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 24 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: April 12th, 2019, 3:08 pm 
Offline
Senior User
Senior User

Joined: September 7th, 2018, 9:00 am
Posts: 99
here I am ... after click on COMPILE ... error compiling: name expected :-/

EDIT

It expects a name here:
var httpClient : THttpClient;


Top
 Profile  
Reply with quote  
PostPosted: April 12th, 2019, 3:51 pm 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 7849
Location: Aachen (Germany)
Sorry, my fault. Function variable blocks only need the var keyword once.
Also I forgot the most important part of initializing the httpClient with the URL. Somehow forgot to copy that from my sample code into your modified function.

Here's the fixed code:
Code:
FUNCTION update(status, picture : String) : String;
var getStr, returnstr : String;
httpClient : THttpClient;
BEGIN
   WriteLn(picture);

   // URLEncode Blanks and Special Chars
   status := URLEncode(status);
   picture := URLEncode(picture);

   //getStr := 'http://www.sam-song.info/twitter/'
   getStr := RadioSocial
   + '?message=' + status
    + '&picture=' + picture
   + '&title=' + URLEncode(Song['title'])
    + '&artist=' + URLEncode(Song['artist'])
   + '&album=' + URLEncode(Song['album'])
    + '&duration=' + URLEncode(Song['duration'])
   + '&shop=' + URLEncode(Song['buycd'])
    + '&songtype=' + Song['songtype'];

  httpClient := THttpClient.Create(getStr);

   //WebToStr(getStr); // Tormy
   // Here goes the magic!

//   WebToFile(PathFiles + 'webresponse.txt', getStr);
   httpClient.Get;
   while not httpClient.ResponseReady do
     Pal.WaitForTime('+00:00:01');

  // HTTP Status Codes: 200 = OK, 404 = NOT FOUND, 403 = Forbidden, 500 = Generic Server error
  IF httpClient.ResponseCode = 200 THEN
    returnstr := httpClient.ResponseData;

  result := returnstr;
END;



This is the full example of how the THttpClient shold work:
Code:
var httpClient : THttpClient;
var headers : TStrings = TStringList.Create;
var T : Integer;
var url : string = 'http://myserver.com/myapi/';
 
httpClient := THttpClient.Create(url);
 
//Customize headers
httpClient.AddHeader('User-Agent: sambc/2017.8'); //Override default User-Agent
httpClient.AddHeader('X-CUSTOM-HEADER: My custom header code'); //Add custom header
 
//HTTP Basic Auth support
httpClient.Username := 'myusername';
httpClient.Password := 'pass123';
httpClient.MaxRedirects := 5;
 
//If set, will save data to file instead of storing result in 'httpClient.ResponseData'
httpClient.Filename := DATA_PATH+'URL-TO-FILE.txt';
 
//Choose VERB to use + Data type to sent
//Note: httpClient is SINGLE USE only. Create new instance for each web request.
httpClient.Get;
//httpClient.Head;
//httpClient.Delete;
//httpClient.Post('My Post Data','text/text');
//httpClient.Put('My Put Data','text/text');
//httpClient.PostFile(DATA_PATH+'EventLog.log','text/text');
//httpClient.PutFile(DATA_PATH+'EventLog.log','text/text');
 
//Requests happen in background - so make sure to wait for it to complete!
while not httpClient.ResponseReady do
  Pal.WaitForTime('+00:00:01');

//Print out response data
PAL.LockExecution;
  WriteLn('EffectiveUrl='+httpClient.EffectiveUrl);
  WriteLn('Code='+IntToStr(httpClient.ResponseCode));
  WriteLn('Response='+httpClient.ResponseData);
  WriteLn('Headers=>');
  httpClient.ReadResponseHeaders(headers);

  for T := 0 to headers.count-1 do
     WriteLn(headers[T]);

PAL.UnLockExecution;

//Cleanup
httpClient.Free;
headers.Free;



And this is an example with a minimalistic real-world API wrapped in a function:
Code:
FUNCTION update(url : String) : String; forward;


WriteLn(update('https://ident.me/.json'));


FUNCTION update(url : String) : String;
var httpClient : THttpClient;
returnstr : String;

BEGIN
httpClient := THttpClient.Create(url);
httpClient.Get;

while not httpClient.ResponseReady do
  Pal.WaitForTime('+00:00:01');

//Cleanup

IF httpClient.ResponseCode = 200 THEN
  returnstr := httpClient.ResponseData;

WriteLn(returnstr);
httpClient.Free;

result := returnstr;
END;

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

We're offering custom PAL / PHP code and general SAM assistance at palscripts.com

My Project:
Send "Now Playing" from SAM to Twitter and/or Facebook | Sourcecode


Top
 Profile  
Reply with quote  
PostPosted: April 12th, 2019, 4:04 pm 
Offline
Senior User
Senior User

Joined: September 7th, 2018, 9:00 am
Posts: 99
ok it's running now ... for the whole night there is deep music ...thus 1h each ... tomorrow I will see if all of them are signalled to the PHP and I will monitor the situation in these few days to be sure it works flawlessly

I will keep you in touch


Top
 Profile  
Reply with quote  
PostPosted: April 12th, 2019, 4:16 pm 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 7849
Location: Aachen (Germany)
Tormy wrote:
I will keep you in touch

I'm eager to hear how it worked out after the weekend.
Still find it very strange that it seemed to fail. If the switch to a different HTTP stack doesn't help, the only thing I still have in mind is replacing the blocking WebToStr call with a non-blocking variant (either WebToFile or THttpClient)

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

We're offering custom PAL / PHP code and general SAM assistance at palscripts.com

My Project:
Send "Now Playing" from SAM to Twitter and/or Facebook | Sourcecode


Top
 Profile  
Reply with quote  
PostPosted: April 13th, 2019, 1:32 am 
Offline
Senior User
Senior User

Joined: September 7th, 2018, 9:00 am
Posts: 99
Mastacheata wrote:
Tormy wrote:
I will keep you in touch

I'm eager to hear how it worked out after the weekend.
Still find it very strange that it seemed to fail. If the switch to a different HTTP stack doesn't help, the only thing I still have in mind is replacing the blocking WebToStr call with a non-blocking variant (either WebToFile or THttpClient)



Already failed :-/

Here in attachment the screenshot.
on the left what the script received, on the right: what SAM broadcasted

The highlighted in red, are the ones that SAM failed

This is only an offprint. The failure still in progress while I'm writing

In fact when SAM fails, also the player on the web portal is failing, because it relies on the call of SAM.
So that if a broadcast is showing up there, clicking play, you can listen something totally different

In other words: if SAM is behaving so, it's dramatically unreliable


Attachments:
File comment: Left: log from the PHP script
Right: what SAM broadcast

SAM 1.JPG
SAM 1.JPG [ 236.77 KiB | Viewed 284 times ]
Top
 Profile  
Reply with quote  
PostPosted: April 13th, 2019, 7:28 am 
Offline
Senior User
Senior User

Joined: September 7th, 2018, 9:00 am
Posts: 99
SAM is not calling!!! I did verify now.
The scripts sends the instructions, but SAM doesn't call

EDIT
I'm investigating on the network connection
Server > Router > MoDem > Provider


Top
 Profile  
Reply with quote  
PostPosted: April 13th, 2019, 1:55 pm 
Offline
Senior User
Senior User

Joined: September 7th, 2018, 9:00 am
Posts: 99
I wouldn't want to jump for happiness for nothing, but it seems solved and not only that.

I was desperate, however I implemented the Function you suggested and I added this line after the
Code:
PAL.loop := true;
at the very begin of the script


Code:
PAL.LockExecution;


Magically not only from that moment on, it didn't skip any song any longer, but also the "double posts" on twitter (the old issue I had), vanished.
I know this instruction is not particularly suggested due priority issue, but it's a fact: in my case it worked out.

The Function you suggested to me, is now stable on that script because it's simple elegant and functional, and together with that line of code, is working really good.
I would like to have a good week end now :-)


Top
 Profile  
Reply with quote  
PostPosted: April 15th, 2019, 1:20 pm 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 7849
Location: Aachen (Germany)
If you added the LockExecution, did you remove the now nested LockExecutin/UnlockExecution block and did you include a new UnlockExecution at the very end (before the function is implemented).

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

We're offering custom PAL / PHP code and general SAM assistance at palscripts.com

My Project:
Send "Now Playing" from SAM to Twitter and/or Facebook | Sourcecode


Top
 Profile  
Reply with quote  
PostPosted: April 15th, 2019, 1:39 pm 
Offline
Senior User
Senior User

Joined: September 7th, 2018, 9:00 am
Posts: 99
Mastacheata wrote:
If you added the LockExecution, did you remove the now nested LockExecutin/UnlockExecution block and did you include a new UnlockExecution at the very end (before the function is implemented).


Right. Of course this is ont "for free" ... sometimes for few seconds the interface is "suspended" but streaming is not froze, and everything works. From taht moment on it didn't skip any song


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 24 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group