I can't find any HTTPSocket examples.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

I can't find any HTTPSocket examples.

Mytts
So I'm doing a schoolproject in which we have to modify scratch, which is done using squeak. The problem is the teacher thought it was made in python (Because that's how you add mods) and as such we suddenly have a somewhat rushed assignment in a language we have no experience with.

The problem isn't we really don't have time to learn the smalltalk and the modication is not very heavy, so I originally hoped to just find a few examples of how to do stuff and mostly just modify them to our needs. What I'm trying to achieve is relatively simple, calling a .php file on our server. It doesn't take any arguments and doesn't return anything, so I simply just need the server to realize the script is getting called.

I originally wanted to do it using HTTPClient, but my squeak doesn't seem to have this library. I found HTTPSocket however and it seemed to be able to do the job just fine, except I have no idea how to use the class. Everything I try I just get a different error and I'm not sure where to go from here. So any example or just help on how to use the instance/class would be highly appreciated. An attempt I have tried is this one:



CallingPHP
"Used to upload the game"

| |
       
HTTPSocket httpGet: 'http://shgamecrew.dk'.



It seems like HttPSocket doesn't need to be instantiated from what I've gathered, so I thought this would be enough, but alas it seems not. I get a PrimitiveFailed error (Which I have also no idea what means).

Reply | Threaded
Open this post in threaded view
|

Re: I can't find any HTTPSocket examples.

JohnReed Maffeo


> Sent: Thursday, October 02, 2014 at 3:05 AM
> From: Mytts <[hidden email]>
> To: [hidden email]
> Subject: [Newbies] I can't find any HTTPSocket examples.
>
> So I'm doing a schoolproject in which we have to modify scratch, which is
> done using squeak. The problem is the teacher thought it was made in python
> (Because that's how you add mods) and as such we suddenly have a somewhat
> rushed assignment in a language we have no experience with.
>
> The problem isn't we really don't have time to learn the smalltalk and the
> modication is not very heavy, so I originally hoped to just find a few
> examples of how to do stuff and mostly just modify them to our needs. What
> I'm trying to achieve is relatively simple, calling a .php file on our
> server. It doesn't take any arguments and doesn't return anything, so I
> simply just need the server to realize the script is getting called.
>
> I originally wanted to do it using HTTPClient, but my squeak doesn't seem to
> have this library. I found HTTPSocket however and it seemed to be able to do
> the job just fine, except I have no idea how to use the class. Everything I
> try I just get a different error and I'm not sure where to go from here. So
> any example or just help on how to use the instance/class would be highly
> appreciated. An attempt I have tried is this one:
>
>
>
> CallingPHP
> "Used to upload the game"
>
> | |
>
> HTTPSocket httpGet: 'http://shgamecrew.dk'.
>
>
>
> It seems like HttPSocket doesn't need to be instantiated from what I've
> gathered, so I thought this would be enough, but alas it seems not. I get a
> PrimitiveFailed error (Which I have also no idea what means).
>

Which version of Squeak are you using on what platform. I pasted your example into a Workspace in Squeak4.5
latest update: #13663 on Microsoft Windows [Version 6.1.7601] and inspected it. An instance of #RWBinaryOrTextStream was returned. No errors. What is the test of the errors you are getting?

>From your description of you goal, it sounds to me like you would be interested in using #OSProcess.
I recently wrote a method to create a complex script file on my computer and then use #OSProcess to execute it.

You might want to use the #HTTPSocket if you want to invoke your program as a cgi script. Depends on your requirements. You example is just opening a web page.

Personally, I don't see either option as a solution to rushed assignment in a language in which you have no experience.

jrm
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: I can't find any HTTPSocket examples.

Mytts
Hi jrm, thanks for the help. I'm using version 4.1.1 (The newest versions I thought) running on a windows.

The errors I'm getting are: "PrimitiveFailed error".

I realize this is not an ideal solution. The problem is this is an exam project so I need to get it working, I need to call a PHP file from squeak in some way. Once I've successfully called it however, the rest of the assignment is in langauges that I am very familiar with, so that should be no problem.
Reply | Threaded
Open this post in threaded view
|

Re: I can't find any HTTPSocket examples.

Levente Uzonyi-2
On Thu, 2 Oct 2014, Mytts wrote:

> Hi jrm, thanks for the help. I'm using version 4.1.1 (The newest versions I
> thought) running on a windows.

4.1.1 is the version of the VM, but what's more interesting is the version
of the image you're using.

>
> The errors I'm getting are: "PrimitiveFailed error".

It's hard to say anything without seeing the stack trace. Normally a file
named SqueakDebug.log is generated when an error happens, which contains
the details.


Levente

>
> I realize this is not an ideal solution. The problem is this is an exam
> project so I need to get it working, I need to call a PHP file from squeak
> in some way. Once I've successfully called it however, the rest of the
> assignment is in langauges that I am very familiar with, so that should be
> no problem.
>
>
>
> --
> View this message in context: http://forum.world.st/I-can-t-find-any-HTTPSocket-examples-tp4781987p4782145.html
> Sent from the Squeak - Beginners mailing list archive at Nabble.com.
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: I can't find any HTTPSocket examples.

Mytts
The error stack is as following:

NetNameResolver class(Object)>>error:
NetNameResolver class(Object)>>primitiveFailed
NetNameResolver class>>primNameResolverStatus
NetNameResolver class>>resolverStatus
NetNameResolver class>>initializeNetworkIfFail:
Socket>>initializeNetwork
HTTPSocket class>>httpGetDocument:args:accept:request:
HTTPSocket class>>httpGetDocument:args:accept:
HTTPSocket class>>httpGet:args:accept:
HTTPSocket class>>httpGet:accept:

I'm not entirely sure how to check wat version the image is, but i did find that it was created in a squeak 2.8 environment.
Reply | Threaded
Open this post in threaded view
|

Re: I can't find any HTTPSocket examples.

dcorking
On Fri, Oct 3, 2014 at 4:33 PM, Mytts wrote:

> I'm not entirely sure how to check wat version the image is, but i did find
> that it was created in a squeak 2.8 environment.

That is a Scratch image (as you said - sorry.) I guess Scratch 1.4 as
that was the last version of Scratch to be made in Squeak.

Brief comments on stack trace:

primNameResolverStatus was supposed to resolve the DNS name
shgamecrew.dk using some C code in your Squeak virtual machine. (You
probably figured that from the source code.)

Sadly I can't guess what went wrong with any confidence.

It looks to me like you used the GET method correctly, as your code
succeeds and retrieves your home page, on my Linux version of Scratch
1.4

    foo := HTTPSocket httpGet: 'http://shgamecrew.dk'

    foo inspect

It seems to me that something is the matter with your installation,
rather than your knowledge of Squeak. Check if your Scratch is able to
connect to the MIT server. As you are in a hurry I think that you
could get away with the dirty hack of hard coding the value of t6 as
your IP address 46.30.212.164 to bypass the name resolver.  But
naturally, that could only help if the problem is in the resolver,
rather than elsewhere in your networking stack.

Have fun!

David
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: I can't find any HTTPSocket examples.

Mytts
Thanks a lot for the help really! At least I know that my script is working then, so I will have to look if something else is the matter, maybe squeak is denied access to the internet or something. Thank you very much for your help! ^^
(And yes it is Scratch 1.4) ^^
Reply | Threaded
Open this post in threaded view
|

Re: I can't find any HTTPSocket examples.

dcorking
Mytts,

I think it unlikely that my suggested dirty hack would fix your problem,
but just in case, I noticed that in Squeak, an IPv4 address is a Byte Array.

So this message *might* help (at the appropriate point in a throwaway
hacked version of the
HttpSocket>>httpGetDocument:args:accept:request: method)

    t6 := #(46 30 212 164) asByteArray.

Have fun!

David
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: I can't find any HTTPSocket examples.

Levente Uzonyi-2
In reply to this post by Mytts
On Fri, 3 Oct 2014, Mytts wrote:

> The error stack is as following:
>
> NetNameResolver class(Object)>>error:
> NetNameResolver class(Object)>>primitiveFailed
> NetNameResolver class>>primNameResolverStatus
> NetNameResolver class>>resolverStatus
> NetNameResolver class>>initializeNetworkIfFail:
> Socket>>initializeNetwork
> HTTPSocket class>>httpGetDocument:args:accept:request:
> HTTPSocket class>>httpGetDocument:args:accept:
> HTTPSocket class>>httpGet:args:accept:
> HTTPSocket class>>httpGet:accept:
>
> I'm not entirely sure how to check wat version the image is, but i did find
> that it was created in a squeak 2.8 environment.

I suspect that the VM you're using is "too new" for that image. Squeak 2.8
used numbered primitives for network access, while current Squeak images
use named primitives and a separate plugin (SocketPlugin). I suspect that
the 4.1.1 VM doesn't support those numbered primitives anymore[1].
I suggest you to try running the image with a Scratch-compatible VM, or if
you're up for some challenges, you can try using the named primitives.


Levente

[1] http://bugs.squeak.org/view.php?id=7454

>
>
>
> --
> View this message in context: http://forum.world.st/I-can-t-find-any-HTTPSocket-examples-tp4781987p4782331.html
> Sent from the Squeak - Beginners mailing list archive at Nabble.com.
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners