This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#26 2011-11-30 10:49:24

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Lets make a wwm!!

ohaiderstudios wrote:

AARGH! WinSock with C++ is HARD!!!  hmm
Should I switch to another language????
If so, what one do you think would be best (hit me with anything...I can always look up tutorials online)

I personally like Python, most of the complicated socket stuff is done for you.

Code:

import socket

HOST = "127.0.0.1" # Host IP
PORT = 42002 # My unofficial Scratch Server port :P

con=socket.socket( ) # Define the socket type.
con.connect((HOST, PORT)) # Connects to the Host/Server IP Address.

con.send('Hello!')
print con.recv(1024) # 1024 bytes I think, or Kilobytes

con.close()

You may even see some resemblance of C++ ( probably not, except for the import ).  smile

I learned Python Networking here: http://ilab.cs.byu.edu/python/

Last edited by Magnie (2011-11-30 10:51:50)

Offline

 

#27 2011-11-30 16:18:48

flashgocrazy
Scratcher
Registered: 2011-01-12
Posts: 500+

Re: Lets make a wwm!!

ohaiderstudios wrote:

Pecola1 wrote:

flashgocrazy wrote:

here is about mesh

lets make a world wide mesh system that's easier to use and install.

it would have ....

password protected wwms
php codding
and more!

if your a dev, post your code/tuts for wwm
down there!
|
|
|
U

Ever heard of Scratch Live? Its in claw, it basically posts variables online.

Are you asking him about scratch live? He's been posting all over the place asking for tutorials  tongue

I'd be willing to be a PHP coder/HTML coder

ohaiderstudios, did you sign up for the worldzord forums?


◕‿◕

Offline

 

#28 2011-11-30 17:54:06

flashgocrazy
Scratcher
Registered: 2011-01-12
Posts: 500+

Re: Lets make a wwm!!

bump


◕‿◕

Offline

 

#29 2011-11-30 18:40:10

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: Lets make a wwm!!

flashgocrazy wrote:

ohaiderstudios, did you sign up for the worldzord forums?

Yes.


Fork Clamor on GitHub!

Offline

 

#30 2011-11-30 18:43:46

flashgocrazy
Scratcher
Registered: 2011-01-12
Posts: 500+

Re: Lets make a wwm!!

ohaiderstudios wrote:

flashgocrazy wrote:

ohaiderstudios, did you sign up for the worldzord forums?

Yes.

ok added as dev  tongue


◕‿◕

Offline

 

#31 2011-11-30 22:24:53

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: Lets make a wwm!!

Magnie wrote:

So those people out there hosting Minecraft servers and advertising here on Scratch, mind lending some space and a port?  tongue

I'm thinking about renting a VPS for all my web experiments and other stuffz, so maybe it will be I who will provide server space...


Fork Clamor on GitHub!

Offline

 

#32 2011-11-30 22:29:25

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Lets make a wwm!!

ohaiderstudios wrote:

Magnie wrote:

So those people out there hosting Minecraft servers and advertising here on Scratch, mind lending some space and a port?  tongue

I'm thinking about renting a VPS for all my web experiments and other stuffz, so maybe it will be I who will provide server space...

Well, that would be nice.  smile  Do you plan on writing the "Scratch Live" clone in Python? It shouldn't be to hard to write it. I can use a template server and just add a few lines of code and it'll be done. It will be the link between the two that I will have trouble with ( well not that much trouble, actually, it might be just as simple ).

Offline

 

#33 2011-11-30 22:37:34

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: Lets make a wwm!!

Magnie wrote:

ohaiderstudios wrote:

Magnie wrote:

So those people out there hosting Minecraft servers and advertising here on Scratch, mind lending some space and a port?  tongue

I'm thinking about renting a VPS for all my web experiments and other stuffz, so maybe it will be I who will provide server space...

Well, that would be nice.  smile  Do you plan on writing the "Scratch Live" clone in Python? It shouldn't be to hard to write it. I can use a template server and just add a few lines of code and it'll be done. It will be the link between the two that I will have trouble with ( well not that much trouble, actually, it might be just as simple ).

Yeah, I am officially switching to Python...SO much easier!  tongue
So basically, the client would connect to Scratch and the server? Would it use 2 different ports or something? Basically, I'm teaching myself Python as I go along.  tongue


Fork Clamor on GitHub!

Offline

 

#34 2011-11-30 22:46:33

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: Lets make a wwm!!

What's wrong with this line of Python...

Code:

print "Successfully connected to Scratch."

It says that there's a syntax error and highlights the last quotation mark.


Fork Clamor on GitHub!

Offline

 

#35 2011-11-30 22:55:10

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Lets make a wwm!!

ohaiderstudios wrote:

What's wrong with this line of Python...

Code:

print "Successfully connected to Scratch."

It says that there's a syntax error and highlights the last quotation mark.

If you are using Python 3.0 it is print("Stuff"). I use 2.7, so just in case you downloaded 3.0 instead.

And yes, it would require two ports for the client, just one for the server. With the client, it will connect to Scratch through Remote Connections on port 42001, and then connect to the server on port 42002 ( my unofficial Scratch Server port, which I think I said earlier... ).

Last edited by Magnie (2011-11-30 22:57:08)

Offline

 

#36 2011-11-30 23:04:31

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: Lets make a wwm!!

Magnie wrote:

ohaiderstudios wrote:

What's wrong with this line of Python...

Code:

print "Successfully connected to Scratch."

It says that there's a syntax error and highlights the last quotation mark.

If you are using Python 3.0 it is print("Stuff"). I use 2.7, so just in case you downloaded 3.0 instead.

And yes, it would require two ports for the client, just one for the server. With the client, it will connect to Scratch through Remote Connections on port 42001, and then connect to the server on port 42002 ( my unofficial Scratch Server port, which I think I said earlier... ).

Alright, thanks!


Fork Clamor on GitHub!

Offline

 

#37 2011-11-30 23:05:54

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Lets make a wwm!!

ohaiderstudios wrote:

Magnie wrote:

ohaiderstudios wrote:

What's wrong with this line of Python...

Code:

print "Successfully connected to Scratch."

It says that there's a syntax error and highlights the last quotation mark.

If you are using Python 3.0 it is print("Stuff"). I use 2.7, so just in case you downloaded 3.0 instead.

And yes, it would require two ports for the client, just one for the server. With the client, it will connect to Scratch through Remote Connections on port 42001, and then connect to the server on port 42002 ( my unofficial Scratch Server port, which I think I said earlier... ).

Alright, thanks!

Do you want to use 2.7 or 3.0?

Also, sorry for hijacking your thread Flashgocrazy. Hope you don't mind.  tongue

Offline

 

#38 2011-11-30 23:48:58

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: Lets make a wwm!!

Magnie wrote:

ohaiderstudios wrote:

Magnie wrote:


If you are using Python 3.0 it is print("Stuff"). I use 2.7, so just in case you downloaded 3.0 instead.

And yes, it would require two ports for the client, just one for the server. With the client, it will connect to Scratch through Remote Connections on port 42001, and then connect to the server on port 42002 ( my unofficial Scratch Server port, which I think I said earlier... ).

Alright, thanks!

Do you want to use 2.7 or 3.0?

Also, sorry for hijacking your thread Flashgocrazy. Hope you don't mind.  tongue

I'm using 3.3, which is the latest.


Fork Clamor on GitHub!

Offline

 

#39 2011-11-30 23:59:08

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Lets make a wwm!!

ohaiderstudios wrote:

Magnie wrote:

ohaiderstudios wrote:

Alright, thanks!

Do you want to use 2.7 or 3.0?

Also, sorry for hijacking your thread Flashgocrazy. Hope you don't mind.  tongue

I'm using 3.3, which is the latest.

3.X is the new series of Python, 2.X is another series of versions. They are both two separate projects and both are being developed.

Last edited by Magnie (2011-12-01 00:05:44)

Offline

 

#40 2011-12-01 00:01:15

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: Lets make a wwm!!

Another quick Python question:
I get a

Python Shell wrote:

ValueError: bad typecode (must be b, B, u, h, H, i, I, l, L, f or d)

When I have the code

Code:

array('c')

Fork Clamor on GitHub!

Offline

 

#41 2011-12-01 00:07:33

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Lets make a wwm!!

ohaiderstudios wrote:

Another quick Python question:
I get a

Python Shell wrote:

ValueError: bad typecode (must be b, B, u, h, H, i, I, l, L, f or d)

When I have the code

Code:

array('c')

Arrays/Lists are defined like:

Code:

variable = ['item0 string', int(5)]

Though I'm not sure what you are trying to do.  hmm

Offline

 

#42 2011-12-01 00:19:22

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: Lets make a wwm!!

Magnie wrote:

ohaiderstudios wrote:

Another quick Python question:
I get a

Python Shell wrote:

ValueError: bad typecode (must be b, B, u, h, H, i, I, l, L, f or d)

When I have the code

Code:

array('c')

Arrays/Lists are defined like:

Code:

variable = ['item0 string', int(5)]

Though I'm not sure what you are trying to do.  hmm

I'm trying to figure out the code on the Scratch Wiki Page


Fork Clamor on GitHub!

Offline

 

#43 2011-12-01 00:30:01

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Lets make a wwm!!

ohaiderstudios wrote:

Magnie wrote:

ohaiderstudios wrote:

Another quick Python question:
I get a

When I have the code

Code:

array('c')

Arrays/Lists are defined like:

Code:

variable = ['item0 string', int(5)]

Though I'm not sure what you are trying to do.  hmm

I'm trying to figure out the code on the Scratch Wiki Page

Ohh. That's 2.5 Python ( only for 2.X  hmm  ) so I'm not sure if it will work with 3.X

Offline

 

#44 2011-12-01 00:38:48

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: Lets make a wwm!!

Magnie wrote:

ohaiderstudios wrote:

Magnie wrote:


Arrays/Lists are defined like:

Code:

variable = ['item0 string', int(5)]

Though I'm not sure what you are trying to do.  hmm

I'm trying to figure out the code on the Scratch Wiki Page

Ohh. That's 2.5 Python ( only for 2.X  hmm  ) so I'm not sure if it will work with 3.X

Then I'm in trouble  tongue


Fork Clamor on GitHub!

Offline

 

#45 2011-12-01 01:10:15

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Lets make a wwm!!

ohaiderstudios wrote:

Magnie wrote:

ohaiderstudios wrote:


I'm trying to figure out the code on the Scratch Wiki Page

Ohh. That's 2.5 Python ( only for 2.X  hmm  ) so I'm not sure if it will work with 3.X

Then I'm in trouble  tongue

Hehe, of course I've been saying this the whole time but how about you get 2.7 instead?  tongue

Offline

 

#46 2011-12-01 01:18:59

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: Lets make a wwm!!

Magnie wrote:

ohaiderstudios wrote:

Magnie wrote:


Ohh. That's 2.5 Python ( only for 2.X  hmm  ) so I'm not sure if it will work with 3.X

Then I'm in trouble  tongue

Hehe, of course I've been saying this the whole time but how about you get 2.7 instead?  tongue

Okay...reinstalling as I type this!  tongue

I just like to have the latest version of everything...it makes me feel up to date...  tongue


Fork Clamor on GitHub!

Offline

 

#47 2011-12-01 01:22:03

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Lets make a wwm!!

ohaiderstudios wrote:

Magnie wrote:

ohaiderstudios wrote:


Then I'm in trouble  tongue

Hehe, of course I've been saying this the whole time but how about you get 2.7 instead?  tongue

Okay...reinstalling as I type this!  tongue

I just like to have the latest version of everything...it makes me feel up to date...  tongue

Yeah I understand, when I looked at 3.0 when it came out I saw that they had changed the syntax and I decided not to get it. Though they were still working on 2.X so I thought there wouldn't be a need to relearn how to program Python.

Offline

 

#48 2011-12-01 11:17:27

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: Lets make a wwm!!

Magnie wrote:

ohaiderstudios wrote:

Magnie wrote:


Hehe, of course I've been saying this the whole time but how about you get 2.7 instead?  tongue

Okay...reinstalling as I type this!  tongue

I just like to have the latest version of everything...it makes me feel up to date...  tongue

Yeah I understand, when I looked at 3.0 when it came out I saw that they had changed the syntax and I decided not to get it. Though they were still working on 2.X so I thought there wouldn't be a need to relearn how to program Python.

Alrighty, now I'm not getting any errors...


Fork Clamor on GitHub!

Offline

 

#49 2011-12-01 13:12:16

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: Lets make a wwm!!

ohaiderstudios wrote:

Magnie wrote:

ohaiderstudios wrote:


Okay...reinstalling as I type this!  tongue

I just like to have the latest version of everything...it makes me feel up to date...  tongue

Yeah I understand, when I looked at 3.0 when it came out I saw that they had changed the syntax and I decided not to get it. Though they were still working on 2.X so I thought there wouldn't be a need to relearn how to program Python.

Alrighty, now I'm not getting any errors...

Since the Windows doesn't work very well with the module "select" and the server ( http://ilab.cs.byu.edu/python/threadingmodule.html ) I want to use uses select, I have to modify it so it doesn't need it, since select is only used to end the server manually without the pressing Ctrl+C or some other way:

Code:

#!/usr/bin/env python 

""" 
This is like a comment for Python.
""" 

import socket 
import sys 
import threading 

class Server: 
    def __init__(self): 
        self.host = '' 
        self.port = 50000 
        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() 
        running = 1 
        while running: 
                # handle the server socket 
                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 

    def run(self): 
        running = 1 
        while running: 
            data = self.client.recv(self.size) 
            if data: 
                self.client.send(data) 
            else: 
                self.client.close() 
                running = 0 

if __name__ == "__main__": 
    s = Server() 
    s.run()

So that code is compatible with Windows ( while the one on the site is not ).

We will need to decide if the "decoding" of the Scratch broadcasts and variable changes should be done by the client or server.

Here was my original attempt at making the this type of system ( but it didn't get enough popularity so I haven't really updated it in a while ) : http://scratch.mit.edu/forums/viewtopic.php?id=50354

This is the parser I used:

Code:

def parseData(str):
    #Check for a broadcast
    e = re.search('broadcast\s\"(.*)\"',str)
    if e:
        #We have a broadcast!
        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!
        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!
        sensorUpdateIn(e.group(1),e.group(2))

I can just change the function names to ones that I will use or just use the same ones.

Offline

 

#50 2011-12-01 13:16:58

ohaiderstudios
Scratcher
Registered: 2010-10-31
Posts: 100+

Re: Lets make a wwm!!

Magnie wrote:

ohaiderstudios wrote:

Magnie wrote:


Yeah I understand, when I looked at 3.0 when it came out I saw that they had changed the syntax and I decided not to get it. Though they were still working on 2.X so I thought there wouldn't be a need to relearn how to program Python.

Alrighty, now I'm not getting any errors...

Since the Windows doesn't work very well with the module "select" and the server ( http://ilab.cs.byu.edu/python/threadingmodule.html ) I want to use uses select, I have to modify it so it doesn't need it, since select is only used to end the server manually without the pressing Ctrl+C or some other way:

Code:

#!/usr/bin/env python 

""" 
This is like a comment for Python.
""" 

import socket 
import sys 
import threading 

class Server: 
    def __init__(self): 
        self.host = '' 
        self.port = 50000 
        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() 
        running = 1 
        while running: 
                # handle the server socket 
                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 

    def run(self): 
        running = 1 
        while running: 
            data = self.client.recv(self.size) 
            if data: 
                self.client.send(data) 
            else: 
                self.client.close() 
                running = 0 

if __name__ == "__main__": 
    s = Server() 
    s.run()

So that code is compatible with Windows ( while the one on the site is not ).

We will need to decide if the "decoding" of the Scratch broadcasts and variable changes should be done by the client or server.

Here was my original attempt at making the this type of system ( but it didn't get enough popularity so I haven't really updated it in a while ) : http://scratch.mit.edu/forums/viewtopic.php?id=50354

This is the parser I used:

Code:

def parseData(str):
    #Check for a broadcast
    e = re.search('broadcast\s\"(.*)\"',str)
    if e:
        #We have a broadcast!
        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!
        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!
        sensorUpdateIn(e.group(1),e.group(2))

I can just change the function names to ones that I will use or just use the same ones.

GAAAAHH!!! TOO MUCH RAW CODE!!! MY EYES!!!
jk  tongue
Alright, I'll try to understand all of this  smile


Fork Clamor on GitHub!

Offline

 

Board footer