简体   繁体   中英

Does this Scala Perl/Python architecture make sense

In another question I asked for "the best" language for a certain purpose. Realizing this goal was a bit too much to start, I simplified my idea :) But there were really useful language hints. So I decided on Scala for the desktop-app and consider between Perl and Python on the webserver.

I want to program something like an asynchronous chat (little bit like an email). So you start your program pick your name and add a friend with his unique id. Then you can write him a simple message and when your friends start up his pc, launches the "chat.exe" he receives the mail (internet is required) and is able to answer. No special functions, smiley's or text formatting, just simple for learning purpose.

My concept is: Use Scala for the "chat.exe" (Or is just a "chat.jar" possible?) which communicates via SOCKET with a Perl/Python Framework which handles the requests. So you type "Hello there" and click on send. This message is transfered via SOCKET to a Perl/Python script which reads the request an put this message in a MySQL database. On the otherside the chat.exe of your friend checks for new messages and if there is one, the Perl/Python script transfer the message. Also via SOCKET.

Do you think this works out? Is SOCKET appropriate and fits in? Or perhaps REST? But I think for REST-Requests you have to use the URI (http://example.com/newmessage/user2/user3/Hi_how_are_you). This looks very unsecure.

Look forward to your comments!

Have a nice day,

Kurt

If you ask me, I think Scala is most suitable for the server side. Scala runs on the JVM and Java has a really big ecosystem at the server side. You have a big variety of application servers for every taste (tomcat, jetty, glassfish, etc.).

Chat is a classical use case for actors. I think Akka can inspire you in this area.

You can use wonderful Scala web frameworks like Lift. You can even make a web-based chat. Here is an example of a chat application that uses comet (server push):

http://demo.liftweb.net/chat

About REST: If you feel that it's not secure, then

  1. Use HTTPS to communicate with server
  2. In your example, your intent is to put the message to the server (at least that is how I understood it), so most probably you want to use PUT requests, and in this case the message text would be in the POST request body.

Use Scala for the "chat.exe" (Or is just a "chat.jar" possible?)

Step 1. Figure that out. Actually write some stuff and see what you can build.

which communicates via SOCKET with a Perl/Python Framework which handles the requests.

Not meaningful. All internet communication is done with sockets. Leave this sentence out and you don't lose any meaning.

This message is transfered via SOCKET to a Perl/Python script which reads the request an put this message in a MySQL database.

A little useful information. Sockets, however, go without saying.

On the otherside the chat.exe of your friend checks for new messages and if there is one, the Perl/Python script transfer the message. Also via SOCKET.

Right. Sockets, again, don't mean much.

On top of sockets there are dozens of protocols. FTP, Telnet, HTTP, SMTP, etc., etc.

Step 2 is to figure out which protocol you want to use. REST, by the way is a particular use of HTTP. You should really, really look very closely at HTTP and REST before dismissing them.

This looks very unsecure

Not clear why you're saying this. I can only guess that you don't know about HTTP security features.


A lazy programmer might do this.

  1. Install Python, Django, MySQL-Python and Piston.

  2. Define a Django Model, configure the defaults so that model is exposed as a secure RESTful set of services.

That's sort of it for the server side message GET, POST, PUT and DELETE are all provided by Django, Piston and the Django ORM layer. Authentication can be any of a variety of mechanisms. I'm a big fan of HTTP Digest authentication.

要实现类似的东西,你需要通过一个MQ系统,比如ActiveMQ,而不是使用普通的套接字。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM