How to build my own cloud-data-server?

Questions about GP commands and how to do things

Moderator: MSandro

MSandro
Posts: 162
Joined: Jul 26th, '17, 21:12

How to build my own cloud-data-server?

Post by MSandro » Sep 3rd, '17, 20:41

Hi, I want to create a small cloud based application but I don't want to put all the data on the official GP cloud-data-server, so I'd like to build my ow n cloud server for GP. I don't know what protocol or web service I heave to use for comunication between GP and my server. Is it a GP to GP connection or is GP sending the data to another server-side application?


MSandro
Posts: 162
Joined: Jul 26th, '17, 21:12

Re: How to build my own cloud-data-server?

Post by MSandro » Sep 5th, '17, 10:43

Thank you

SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

Re: How to build my own cloud-data-server?

Post by SimpleSi » Sep 5th, '17, 20:27

I'm having a look at this and I've got somewhere
(Running GP on a raspberry pi with modified CloudServer and MessageServer classes)
I can start a server on port 2002 on my Pi and connect to it from my Win10 but the Pi is not understanding the messages

But its a really good learning process :)
Attachments
0.png

SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

Re: How to build my own cloud-data-server?

Post by SimpleSi » Sep 5th, '17, 22:21

Yippee
I've got GP on Win10 sending message to my own server on a Raspberry Pi

I'll write it up tomorrow and then try and make it work simpler :)
0.png

SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

Re: How to build my own cloud-data-server?

Post by SimpleSi » Sep 6th, '17, 06:35

Ok , to start your own dataserver - you 1st need to create a folder called cloudServer on the computer you are going to use as the server
This folder needs to be in same folder as your GP installation
Then create folder within that called gp

Then import a class like this

Code: Select all

defineClass LocalDataServer morph


script 'LocalDataServer' 103 50 {
start (new 'CloudDataServer')
}
LocalDataServer.gp
(103 Bytes) Downloaded 321 times
and then run the block it creates
If you look in your console window - you should see a message that the server is listening on port 2002

Then to use it from another machine you can just edit CloudDataServer.gp in the GP lib folder and uncomment the 127.0.0.1 line and replace it with IP address of your server (I suggest leaving the digital ocean line alone in case you want to go back using it )

Simon

MSandro
Posts: 162
Joined: Jul 26th, '17, 21:12

Re: How to build my own cloud-data-server?

Post by MSandro » Sep 6th, '17, 17:16

Wow, thank you very much, it is much simpler than I thought.

MSandro
Posts: 162
Joined: Jul 26th, '17, 21:12

Re: How to build my own cloud-data-server?

Post by MSandro » Sep 6th, '17, 19:02

But what I do not understand is: why the CloudDataServer is not automaticaly creating new users if they don't exist. With the default setup we are limited to use only the "gp" user, also in the public cloud-data-server.

So I would suggest to change the file "CloudDataServer.gp" like this:

Code: Select all

method handleGet CloudDataServer msg {
  if ((count (args msg)) < 2) {
	return (newRemoteMessage 'notEnoughArguments' (command msg))
  }
  user = (at (args msg) 1)
  key = (at (args msg) 2)
  if (not (and (isClass user 'String') (isClass key 'String'))) {
	return (newRemoteMessage 'arguments must be strings')
  }
  user = (canonicalizedWord user)
  if (not (contains userNames user)) {
	userNames add user
	makeDirectory (join './cloudServer/' (safeFileName this user)
//  return (newRemoteMessage 'unknownUser' user)
  }
  data = (readFile (join './cloudServer/' (safeFileName this user) '/' (safeFileName this key)) true)
  if (isNil data) {
	return (newRemoteMessage 'fileNotFound' key)
  }
  response = (newRemoteMessage 'ok')
  add (blobs response) data
  return response
}

method handlePut CloudDataServer msg {
  if (or ((count (args msg)) < 2) ((count (blobs msg)) < 1)) {
	return (newRemoteMessage 'notEnoughArguments' (command msg))
  }
  user = (at (args msg) 1)
  key = (at (args msg) 2)
  if (not (and (isClass user 'String') (isClass key 'String'))) {
	return (newRemoteMessage 'arguments must be strings')
  }
  user = (canonicalizedWord user)
  if (not (contains userNames user)) {
	userNames add user
	makeDirectory (join './cloudServer/' (safeFileName this user)
//  return (newRemoteMessage 'unknownUser' user)
  }
  data = (at (blobs msg) 1)
  writeFile (join './cloudServer/' (safeFileName this user) '/' (safeFileName this key)) data
  return (newRemoteMessage 'ok')
}
It doesn't work for me but I hope you know what I mean.
I heave changed the two if statements: "if (not (contains userNames user)) {" so it should add the new user to the list and create the folder.

SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

Re: How to build my own cloud-data-server?

Post by SimpleSi » Sep 6th, '17, 20:51

I think the CloudDataServer is just a very simple testbed and not intended for end use when beta ends

It just shows what can be achieved and lets people try out projects with things like high scores in games or simple turn based networked games

For full use it would need security and logins private/public access etc

MSandro
Posts: 162
Joined: Jul 26th, '17, 21:12

Re: How to build my own cloud-data-server?

Post by MSandro » Sep 7th, '17, 10:55

Yes that seemst to be true, currently there are no security features like encryption and dectryption in GP to realize souch data-servers. GP currently only knows "sha256" and "hash" to create checksums for strings and binary data.

But now I've created my own expandable cloud-data-server for my GP projects. It is now able to automatically create new users (folders). And I use "sha256" for the folder (user) and file (key) names.

Post Reply