ohaiderstudios wrote:
AARGH! WinSock with C++ is HARD!!!
![]()
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.
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 ).
I learned Python Networking here: http://ilab.cs.byu.edu/python/
Last edited by Magnie (2011-11-30 10:51:50)
Offline
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!
|
|
|
UEver 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
![]()
I'd be willing to be a PHP coder/HTML coder
ohaiderstudios, did you sign up for the worldzord forums?
Offline
flashgocrazy wrote:
ohaiderstudios, did you sign up for the worldzord forums?
Yes.
Offline
ohaiderstudios wrote:
flashgocrazy wrote:
ohaiderstudios, did you sign up for the worldzord forums?
Yes.
ok added as dev
Offline
Magnie wrote:
So those people out there hosting Minecraft servers and advertising here on Scratch, mind lending some space and a port?
![]()
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...
Offline
ohaiderstudios wrote:
Magnie wrote:
So those people out there hosting Minecraft servers and advertising here on Scratch, mind lending some space and a port?
![]()
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.
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
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?
![]()
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.
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!
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.
Offline
What's wrong with this line of Python...
print "Successfully connected to Scratch."
It says that there's a syntax error and highlights the last quotation mark.
Offline
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
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!
Offline
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.
Offline
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.![]()
I'm using 3.3, which is the latest.
Offline
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.![]()
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
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
array('c')Offline
ohaiderstudios wrote:
Another quick Python question:
I get aPython 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:
variable = ['item0 string', int(5)]
Though I'm not sure what you are trying to do.
Offline
Magnie wrote:
ohaiderstudios wrote:
Another quick Python question:
I get aPython 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.
![]()
I'm trying to figure out the code on the Scratch Wiki Page
Offline
ohaiderstudios wrote:
Magnie wrote:
ohaiderstudios wrote:
Another quick Python question:
I get a
When I have the codeCode:
array('c')Arrays/Lists are defined like:
Code:
variable = ['item0 string', int(5)]Though I'm not sure what you are trying to do.
![]()
I'm trying to figure out the code on the Scratch Wiki Page
Ohh. That's 2.5 Python ( only for 2.X
) so I'm not sure if it will work with 3.X
Offline
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.
![]()
I'm trying to figure out the code on the Scratch Wiki Page
Ohh. That's 2.5 Python ( only for 2.X
) so I'm not sure if it will work with 3.X
Then I'm in trouble
Offline
ohaiderstudios wrote:
Magnie wrote:
ohaiderstudios wrote:
I'm trying to figure out the code on the Scratch Wiki PageOhh. That's 2.5 Python ( only for 2.X
) so I'm not sure if it will work with 3.X
Then I'm in trouble
![]()
Hehe, of course I've been saying this the whole time but how about you get 2.7 instead?
Offline
Magnie wrote:
ohaiderstudios wrote:
Magnie wrote:
Ohh. That's 2.5 Python ( only for 2.X) so I'm not sure if it will work with 3.X
Then I'm in trouble
![]()
Hehe, of course I've been saying this the whole time but how about you get 2.7 instead?
![]()
Okay...reinstalling as I type this!
I just like to have the latest version of everything...it makes me feel up to date...
Offline
ohaiderstudios wrote:
Magnie wrote:
ohaiderstudios wrote:
Then I'm in trouble![]()
Hehe, of course I've been saying this the whole time but how about you get 2.7 instead?
![]()
Okay...reinstalling as I type this!
![]()
I just like to have the latest version of everything...it makes me feel up to date...![]()
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
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?![]()
Okay...reinstalling as I type this!
![]()
I just like to have the latest version of everything...it makes me feel up to date...![]()
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...
Offline
ohaiderstudios wrote:
Magnie wrote:
ohaiderstudios wrote:
Okay...reinstalling as I type this!![]()
I just like to have the latest version of everything...it makes me feel up to date...![]()
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:
#!/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:
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
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
Alright, I'll try to understand all of this
Offline