Well, you found my other topic. Hope it helped.
By the way: I believe you can just ignore the client and just connect Scratch to the Server without any problem since all the mirror does is just take what Scratch sent it and send that data to the server.
Just make sure to change the server port to 42001 instead of 42002 ( I think )
Last edited by Magnie (2011-05-04 19:35:33)
Offline
well, you mentioned in the other topic that you can do this online. what do I type for join mesh, if that's what you do.(help!!, last question, by the way!!
)
Offline
Magnie wrote:
This should work for Windows, though I haven't tested it:
Code:
#!/usr/bin/env python """ An echo server that uses threads to handle multiple clients at a time. Entering any line of input at the terminal will exit the server. """ import socket import sys import threading from array import array import time import re # Parse Data Definitions def parseData(str): #Check for a broadcast e = re.search('broadcast\s\"(.*)\"',str) if e: #We have a broadcast! return 'parsed = broadcastIn("'+e.group(1)+'")' #Check for a sensor-update with quoted second value (string) e = re.search('sensor-update\s\"(.*?)\"\s\"(.*?)\"',str) if e: #Got one! return 'parsed = sensorUpdateIn("'+e.group(1)+'","'+e.group(2)+'")' #Look for a sensor-update with a numeric second value e = re.search('sensor-update\s\"(.*?)\"\s([-|\d|.]+)',str) if e: #Success! return 'parsed = sensorUpdateIn("'+e.group(1)+'","'+e.group(2)+'")' def sensorUpdateIn(var,value): #print "Scratch changed "+var+" to: "+value return 'sensor-update '+value def broadcastIn(broadcast): #print "Scratch broadcasted: "+broadcast return 'broadcast '+broadcast # End class Server: def __init__(self): self.host = '' self.port = 42002 self.backlog = 5 self.size = 1024 self.server = None self.threads = [] def open_socket(self): try: self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.server.bind((self.host,self.port)) self.server.listen(5) except socket.error, (value,message): if self.server: self.server.close() print "Could not open socket: " + message sys.exit(1) def run(self): self.open_socket() input = [self.server,sys.stdin] running = 1 while running: c = Client(self.server.accept()) c.start() self.threads.append(c) # close all threads self.server.close() for c in self.threads: c.join() class Client(threading.Thread): def __init__(self,(client,address)): threading.Thread.__init__(self) self.client = client self.address = address self.size = 1024 lcs.append([0,0]) #print lcs self.ids = len(lcs)-1 #print self.ids def run(self): #print self.address,'has connected.' running = 1 while running: data = self.client.recv(self.size) if data: exec parseData(data) if parsed == 'broadcast start': # Start/Setup exe = '''sendScratchCommand('sensor-update "x" "'''+str(lcs[self.ids][0])+'''"') sendScratchCommand('sensor-update "y" "'''+str(lcs[self.ids][1])+'''"') ''' # Movement Start elif parsed == 'broadcast up': # Move Up lcs[self.ids][1] += 1 #print lcs exe = '''sendScratchCommand('sensor-update "y" "'''+str(lcs[self.ids][1])+'''"')''' elif parsed == 'broadcast down': # Move Down lcs[self.ids][1] -= 1 #print lcs exe = '''sendScratchCommand('sensor-update "y" "'''+str(lcs[self.ids][1])+'''"')''' elif parsed == 'broadcast left': # Move Left lcs[self.ids][0] -= 1 #print lcs exe = '''sendScratchCommand('sensor-update "x" "'''+str(lcs[self.ids][0])+'''"')''' elif parsed == 'broadcast right': # Move Right lcs[self.ids][0] += 1 #print lcs exe = '''sendScratchCommand('sensor-update "x" "'''+str(lcs[self.ids][0])+'''"')''' # Movement End else: # Unknown Command exe = 'print "Error, no such command."' self.client.send(exe) else: self.client.close() running = 0 if __name__ == "__main__": lcs = [] s = Server() s.run()
BTW, what does this do?
Offline
1. You have to code the Mesh into the Server
2. That is the Windows version of the server.
You should learn a bit of Python before you start making things out of it.
Offline
Magnie wrote:
1. You have to code the Mesh into the Server
2. That is the Windows version of the server.
You should learn a bit of Python before you start making things out of it.![]()
yeah, I should. just tell me a few things
1) I don't know where to put it in (I have an idea)
2) a windows server for...................
Offline
your example mirror, the one on the front page, I run scratch, then open the mirror, and all python does is opens, writes things too fast for me to see, and closes. I debugged it and found nothing wrong. Did I do something wrong there?
Offline
You need to Enable Remote Sensors.
Though the server hasn't been set up for Mesh. It's just a server that you can connect Scratch to. You will need to program whatever you need for the Server yourself.
Anyways: Basic setup to connect to the Server:
1. Turn on the Server/Run it
2. Open Scratch ( and whatever project you want ) and enable Remote Sensor Connections
3. Run the Mirror Client.
Offline
Magnie wrote:
comp500: That would be interesting to see, if you get one up, could you show it?
markyparky56: What do you mean? Having a Single Player Game on a server, you can save Data there and you can access it from any computer, but Single Player Games off-line can only be played on that computer. But I don't understand very much of what you are talking about.Could you explain a little?
Yes but I would need someone to host it for me as i'm not giving out my IP address...
Offline
I might be able to, if you put the code somewhere I may be able to run it for a while for everyone's enjoyment ( until I get yelled at for it taking resources, etc ).
Offline
comp500 wrote:
gsjs wrote:
if only javascript had sockets.
it would make it possible for easy multiplayer 8(
javascript does. its in html5...
I've heard of HTML5. I'm going to use it for the new Kitcat site:). Although, I might switch to xhtml (I just know the !DOCTYPE for xhtml1
) and I don't even know what version of xhtml is out!
Offline
comp500 wrote:
gsjs wrote:
if only javascript had sockets.
it would make it possible for easy multiplayer 8(
javascript does. its in html5...
really? Could you please tell me what they are? I am WAY better at javascript then I am at python, and I don't even know what python is used for!!
Offline
I'm baaaack!
@magnie
I want to make a little program in Visual C#. I dont know if you know any of it, but I can connect to Scratch, but I want to know how to send data to the remote sensors blocks in Scratch from Visual C#. How, in human words, do you do it in Python? Just say something like, "First, I create an aray, then set a variable, etc.". I'm sure it will be simaler to do in Visual C#.
Offline
You could try looking at the Remote Sensors Protocol on the wiki.
Offline
TRocket wrote:
if you understand java better i wrote the same kind of thing here
That actually, suprisingly, helps a lot! Java is very simmaler to C#, so the code makes sense to me.
The wiki doesn't really tell you much. Thats why I posted here.
Offline