Hey guys:
I am trying to make a website using by Python to connect to Scratch(which is on my localhost)
and I hope that can broadcast or receive broadcast...etc. from it .
but, what i try is only get a bad gateway.
Here is my Source Code:
-------------------------------------------------------------
from array import array
import socket
import time
from Tkinter import Tk
from tkSimpleDialog import askstring
root = Tk()
root.withdraw()
import sys
#PORT = 42001
#if HOST == None:
# sys.exit()
print("connecting...")
scratchSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#scratchSock.connect((HOST, PORT))
scratchSock.connect(("localhost", 42001))
print("connected!!Waiting for data...")
def sendScratchCommand(cmd):
n = len(cmd)
a = array('c')
a.append(chr((n >> 24) & 0xFF))
a.append(chr((n >> 16) & 0xFF))
a.append(chr((n >> 8) & 0xFF))
a.append(chr(n & 0xFF))
scratchSock.send(a.tostring() + cmd)
while 1:
time.sleep(0.01)
data = scratchSock.recv(1024)
if data == '\x00\x00\x00\x15broadcast "YesLesson"':
print(data+"1")
if data == '\x00\x00\x00\x13broadcast "YesExam"':
print(data+"2")
I use iis in this case.
--------------------------------------------------------------------------------
I have a few question:
1.Is it possible to creat this kind of python website and connect to Scratch on localhost?or there's another way like connect Scratch and Python both on the website?
2.I've try to make a easy version like:
-1
--------------------------
import socket
print("connecting...")
scratchSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
scratchSock.connect(("localhost", 42001))
print("connected...waiting for data")
---------------------------
-2
--------------------------
import socket
print("connecting...")
sock = socket.socket()
sock.connect(("localhost",42001))
print("connected...waiting for data")
--------------------------
both of them can work when I compiler on localhost
but after I put it on server,it can not work....
Please helllllllllllllllllllllllllllllllllllllllllpppppp me .....
Offline
I don't know any Python, but you can connect to Scratch via it. However, connecting to your own computer would not be possible unless you have port-forwarded 42001. Furthermore, in the python code on the website, you would not want it to connect to localhost; that would mean scratch is running on the website. The ideal situation would be to have the server on the website, and connect to that via scratch.
Offline
SJRCS_011 wrote:
I don't know any Python, but you can connect to Scratch via it. However, connecting to your own computer would not be possible unless you have port-forwarded 42001. Furthermore, in the python code on the website, you would not want it to connect to localhost; that would mean scratch is running on the website. The ideal situation would be to have the server on the website, and connect to that via scratch.
Actually, you can access localhost without any port-forwarding because it's just on your machine behind the router.
Offline
veggieman001 wrote:
SJRCS_011 wrote:
I don't know any Python, but you can connect to Scratch via it. However, connecting to your own computer would not be possible unless you have port-forwarded 42001. Furthermore, in the python code on the website, you would not want it to connect to localhost; that would mean scratch is running on the website. The ideal situation would be to have the server on the website, and connect to that via scratch.
Actually, you can access localhost without any port-forwarding because it's just on your machine behind the router.
but when you put the python on a foreign host, it needs to connect to your computer, so you need to port-forward
What i mean is if the user is on his/her computer, running a scratch server, python on a foreign host cannot connect to it unless his/her router is port-forwarded.
The user also needs a VPS of some sort to run this I think.
Last edited by SJRCS_011 (2012-05-26 11:20:21)
Offline
If I understand what you are trying to do is you want to make a website (in your browser) and then when someone loads that page, it connects to their local Scratch program and then interacts with that.
So, using that method, it won't be possible because that requires client-side Python and nearly no one has that (mostly because of security reasons I'd guess). You'd have better luck with a Java Applet that does that.
Offline
SJRCS_011 wrote:
veggieman001 wrote:
SJRCS_011 wrote:
I don't know any Python, but you can connect to Scratch via it. However, connecting to your own computer would not be possible unless you have port-forwarded 42001. Furthermore, in the python code on the website, you would not want it to connect to localhost; that would mean scratch is running on the website. The ideal situation would be to have the server on the website, and connect to that via scratch.
Actually, you can access localhost without any port-forwarding because it's just on your machine behind the router.
but when you put the python on a foreign host, it needs to connect to your computer, so you need to port-forward
What i mean is if the user is on his/her computer, running a scratch server, python on a foreign host cannot connect to it unless his/her router is port-forwarded.
The user also needs a VPS of some sort to run this I think.
Ah, okay.
It seems like he's using some sort of AMP package.
And yeah, but you'll also need to change it to the IP of your computer from localhost and port forward.
Offline
Magnie wrote:
If I understand what you are trying to do is you want to make a website (in your browser) and then when someone loads that page, it connects to their local Scratch program and then interacts with that.
So, using that method, it won't be possible because that requires client-side Python and nearly no one has that (mostly because of security reasons I'd guess). You'd have better luck with a Java Applet that does that.
sorry,I just have the question
can u say something how can I do with java applet
or u have java applet source code?
thx ur answer
Offline
ki59920 wrote:
Magnie wrote:
If I understand what you are trying to do is you want to make a website (in your browser) and then when someone loads that page, it connects to their local Scratch program and then interacts with that.
So, using that method, it won't be possible because that requires client-side Python and nearly no one has that (mostly because of security reasons I'd guess). You'd have better luck with a Java Applet that does that.sorry,I just have the question
can u say something how can I do with java applet
or u have java applet source code?
thx ur answer
I don't have the source for the current applet I use, but the old source is here. You should probably ask MathWizz about anything related to Java.
Offline
Magnie wrote:
ki59920 wrote:
Magnie wrote:
If I understand what you are trying to do is you want to make a website (in your browser) and then when someone loads that page, it connects to their local Scratch program and then interacts with that.
So, using that method, it won't be possible because that requires client-side Python and nearly no one has that (mostly because of security reasons I'd guess). You'd have better luck with a Java Applet that does that.sorry,I just have the question
can u say something how can I do with java applet
or u have java applet source code?
thx ur answerI don't have the source for the current applet I use, but the old source is here. You should probably ask MathWizz about anything related to Java.
or me
BTW, big necro, might want to report this
Offline