0

Nowadays, we always think like "send your data to a server, it computes it for you, then send you back the response".

But imagine something else : i want my client to compute the data itself.

The question is : is there something like a universal protocol to send actions rather than data through http ? So that the server can send the action to the client, whatever system it uses. If it does not exist, what are the technical difficulties you can face creating this kind of system ?

I'm talking about "static" actions, like mathematical functions for example.

fazega
  • 327
  • 2
  • 13
  • there is no such protocol, try to design one and you will understand why it is impossible :) – Iłya Bursov Jul 27 '17 at 00:36
  • it's not a reproach, it's just to understand what can be the difficulties – fazega Jul 27 '17 at 00:37
  • first difficulty - actions standalone are useless, they need data, which is probably huge dataset (and it is faster to process it on server then send to client), second - security, you actually don't want to send some actions+data to clients – Iłya Bursov Jul 27 '17 at 00:38
  • first - i don't understand, if i have a local database for example ... second - what security ? if the action is summing two numbers for example – fazega Jul 27 '17 at 00:39
  • i'm more talking about the technical difficulties actually – fazega Jul 27 '17 at 00:40
  • me too, now imagine - you've sent action "summarize" to client, what client will do with this information? – Iłya Bursov Jul 27 '17 at 00:40
  • something far more simple, my client has number A and B, i want to send him the function (A,B)=>(A+B) – fazega Jul 27 '17 at 00:41
  • ok, so, server is sending string with data "(a,b)...", client parses this data and recognizes that it should perform some action, right? – Iłya Bursov Jul 27 '17 at 00:43
  • Exactly. It recognizes that it is a function (in its own language !). Perhaps it's not logically possible but i don't think so. We just need a universal language to serialize and deserialize the function. – fazega Jul 27 '17 at 00:44
  • ok, there are bunch of such languages, for example javascript, web server sends html+js and client (browser) executes it – Iłya Bursov Jul 27 '17 at 00:45
  • There is the trick : how can you do so that an android app, or an iOS app or a javascript or a blablabla client system can deserialize it in its own language ? – fazega Jul 27 '17 at 00:46
  • I don't understand what you mean "its own language", client must understand/conform to server's language, otherwise it will not work – Iłya Bursov Jul 27 '17 at 00:48
  • "it will not work" because the system i suggest does not exist or you don't know it – fazega Jul 27 '17 at 00:49
  • because you cannot create anything universal, by definition, you have to define some protocol/alphabet – Iłya Bursov Jul 27 '17 at 00:50
  • Wut ? Data are universal i think they exist. Perhaps you are mentioning the fact that running some code inside of a code is not possible. But it exists ! In java or php for example. – fazega Jul 27 '17 at 00:51
  • you're not reading my comments, if you want to execute some code which is sent by server on client, then client must understand programming language in which this code is written, I gave you real world example of such language. If you want client to understand any arbitrary programming language - it is impossible. – Iłya Bursov Jul 27 '17 at 00:54
  • I read this carefully. The only thing is that you're claiming things without arguments. "it is impossible." prove it. – fazega Jul 27 '17 at 00:56
  • Otherwise i would not have asked this question, if the only answer is "it's impossible" without any arguments, such as logical arguments, historical attempts without success ... – fazega Jul 27 '17 at 00:57
  • it is impossible because I can create two programming language with contradictory syntax, for example in language A string `A+B` will concatenate and produce 'AB'. in language B string `A+B` will summarize ascii codes, and result will be 131, what should universal client do in this case? – Iłya Bursov Jul 27 '17 at 00:58
  • I think you misunderstood something : i have only one language the universal one which is transmitted to clients, which uses their language. So there is only one "A+B" result, the one from the universal language. The difficulty is to translate the string sent in the universal language to the client language, and not just reading this. Otherwise the problem you mentioned would happens because reading "A+B" would lead to different interpretations regarding of the language of the client (if you simply read the string i repeat). – fazega Jul 27 '17 at 01:01
  • I don't understand what you mean "clients, which uses their language" – Iłya Bursov Jul 27 '17 at 01:01
  • are you referring to the programming language which was used to write client? – Iłya Bursov Jul 27 '17 at 01:02
  • A client is just a piece of code connecting to a server. That piece of code is written in a language. Android app uses java, browser uses javascript. – fazega Jul 27 '17 at 01:02
  • oh.... this language absolutely doesn't matter, you don't need to convert from one language to another just to execute it, for example browser is written in C/C++, but it does not convert javascript to C to execute it – Iłya Bursov Jul 27 '17 at 01:03
  • I agree. It does not solve the problem however :p – fazega Jul 27 '17 at 01:05
  • so, you're looking for library which can interpret some programming language, probably you're looking for multi-platform library, AFAIR there are bunch of javascript interpreters for any platform (java, .net, c) – Iłya Bursov Jul 27 '17 at 01:05
  • Finally we are going in the same direction ! An interpreter could do the job, now is it the best solution ? Concerning the transport of the function itself, you've never heard of such a thing ? It seems so common – fazega Jul 27 '17 at 01:07
  • it is best solution to some problems, transport function is soo irrelevant, if you don't like http - use tcp – Iłya Bursov Jul 27 '17 at 01:09
  • You'll still need to transport the string containing the function even if it's written in javascript ... I don't really care about http or not actually – fazega Jul 27 '17 at 01:13
  • so, now you understand that server will continue to send "data" to client, right? this data is "actions" only from client side perspective – Iłya Bursov Jul 27 '17 at 01:15
  • Yes all the network communications work like that. But i don't understand why it seems so "original" to send functions since we already don't only send data through http. Look at WCF for example, they send object definitions, method definitions ... Strange that nobody already thought it would be a good idea to send functions. I absolutely need to tell google to do something about that :p – fazega Jul 27 '17 at 01:19
  • you're not reading my comments, at all, sorry, I cannot continue such conversation – Iłya Bursov Jul 27 '17 at 01:22
  • I'm reading it, i understand that " server will continue to send "data" to client, right? this data is "actions" only from client side perspective". I don't undestand what you're trying to say. It's just that i don't think that the discussion is leading somewhere since you're convinced that this idea is stupid (odd is a better word !), you're saying it yourself "transport function is soo irrelevant" without explanations. Sometimes just getting out of the common ideas can lead to good results. Hope someone will be more open ? – fazega Jul 27 '17 at 01:27
  • have you read this `so, you're looking for library which can interpret some programming language, probably you're looking for multi-platform library, AFAIR there are bunch of javascript interpreters for any platform (java, .net, c) – Ilya Bursov 51 mins ago`? It is the answer to your question. Next step for you is to google "javascript interpreter for XXXX" insert you client's language – Iłya Bursov Jul 27 '17 at 01:56
  • That's definitely a good idea as i said. But as i also said, it may not be the best solution. You answered me it is without arguments, so the discussion is closed i think. Let the others give their point of vue, and thank you for yours ! – fazega Jul 27 '17 at 02:34

1 Answers1

1

You're unfortunately going to run into a problem pretty quick because, technically speaking, a universal language is impossible. Systems are going to have different architecture, different languages available, and different storage means. I believe what you intend (correct me if I'm wrong) is a "widespread" protocol. One way or another, you're going to have to drill down based on your personal use-case.

For a widespread example, you could keep a set of JavaScript files with functions server-side, and refer a web client to the one they need to run it by loading a javascript file during some event. Pass the location of the file and the function name, load it using the link above, then call the JavaScript function by name to run it. I could see this being an admitedly somewhat roundabout solution. This also may work in Java due to its built in JavaScript engine, although I haven't tested it.

Beyond that, I am unaware of anything particularly widespread. Most applications limit what they accept as instructions quite strictly to prevent security breaches (Imagine a SQL Injection that can run free on a client's machine). In fact, JavaScript limits itself quite severely, perhaps most notably in regards to local file reading.

Hopefully this helps with your ideas. Let me know in a comment if you have any questions/issues about what I've said.

dornadigital
  • 167
  • 13
  • Thank god someone understood my point. I also think it's the simplest solution, I'll test it and feed back the performance. Thank you very much for the very interesting article about JS limits (and all your others links as well), actually it can raise deep issues (especially concerning local files ...) ! I didn't really understand the SQL Injection problem however, since the database would be stored on server side, so the server could check if the queries from the client are valid (if queries there are). – fazega Aug 03 '17 at 20:33
  • @fazega: Glad it helped! My apologies for the confusion regarding Sql, that was meant more as a simile than a direct comparison. Basically, the moment you allow strings to be turned into code, client or server side, you run into the classic injection problem. A hacker-proof injection analyzer is the holy-grail of security coding, so you're going to have to limit what queries/commands are acceptable. It all comes back establishing effective limits. – dornadigital Aug 03 '17 at 20:52
  • I see. It's true that the string parsing/unparsing part has to be made very carefully, because of injection-like unexpected issues. – fazega Aug 03 '17 at 21:13