Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Mon Aug 21, 2017 12:49 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Communicating with my app via a socket
PostPosted: Sun Jan 27, 2013 10:27 am 
Offline
User avatar

Joined: Wed Oct 05, 2005 1:21 pm
Posts: 515
Location: United Kingdom
I'm writing an application to help me manage my growing collection of retro game ROMs. I know there are lots of options and other programs out there that do this but I want to write my own.

My approach is to have a small 'server' app that runs continuously in the background. Its preferences can be accessed by clicking a taskbar or menubar icon. The server's role is to index all ROMs in a particular directory and populate a SQLite database with metadata. The server will also be in charge of launching (via the command line) the correct emulator for a chosen ROM.

A second application, the 'client' will be responsible for displaying the information about the ROMs (i.e. a visual browser) and for selecting which emulator to use to run it. I'm looking for the best way to communicate between the two. For instance, the client should be able to request all Super NES games currently indexed in the the 'platformer' genre and the server would return an XML formatted list that can be subsequently parsed. I'm looking for suggestions for the best approach to implement this. Although the server and my client will be written in Real Studio, I'm hoping that other people would be able to interface with the server (for instance from XBMC or Plex) using an API that I publish. This means that the format of communication needs to be a standard of some sort rather than a proprietary Real Software format (which is putting me off things like EasyTCPSocket).

I'm relatively new to networking so I don't want to start this project until I have a good idea of how to lay it out.

I'd really appreciate any advice people have.

Thanks,

MadDoc

_________________
Gorgeous REALbasic controls from Figa Software | My Flickr | My Blog
11" MacBook Air 1.8Ghz i7, 4GB RAM, OSX 10.8.2, RB 2012 r1.1 Pro | iPhone 4S 32GB | Nikon D60


Top
 Profile  
Reply with quote  
 Post subject: Re: Communicating with my app via a socket
PostPosted: Sun Jan 27, 2013 3:08 pm 
Offline
User avatar

Joined: Sun Oct 28, 2012 4:54 am
Posts: 264
Location: Herts, UK
How about having the server stream the emulated rom to the client?

_________________
Real Studio 2012 R2
SysInfo
BackTrack Linux/BackBox Linux/Debian Lenny/Windows 7/Windows 8/OpenWRT/OpenBSD
& Yes it's me in the Avatar


Top
 Profile  
Reply with quote  
 Post subject: Re: Communicating with my app via a socket
PostPosted: Sun Jan 27, 2013 4:17 pm 
Offline
User avatar

Joined: Wed Oct 05, 2005 1:21 pm
Posts: 515
Location: United Kingdom
That's certainly a feature I'm considering implementing once I get the metadata scraping / managing side of things working. There will of course be issues of latency though (amongst many other technical hurdles!).

_________________
Gorgeous REALbasic controls from Figa Software | My Flickr | My Blog
11" MacBook Air 1.8Ghz i7, 4GB RAM, OSX 10.8.2, RB 2012 r1.1 Pro | iPhone 4S 32GB | Nikon D60


Top
 Profile  
Reply with quote  
 Post subject: Re: Communicating with my app via a socket
PostPosted: Sun Jan 27, 2013 4:57 pm 
Offline
User avatar

Joined: Sun Oct 28, 2012 4:54 am
Posts: 264
Location: Herts, UK
I have been working on something similar over the last few months with the Boxee API but had to put to one side due to work commitments.

http://developer.boxee.tv/Main_Page

http://lifehacker.com/5491011/launch-games-and-emulator-roms-from-boxee

_________________
Real Studio 2012 R2
SysInfo
BackTrack Linux/BackBox Linux/Debian Lenny/Windows 7/Windows 8/OpenWRT/OpenBSD
& Yes it's me in the Avatar


Top
 Profile  
Reply with quote  
 Post subject: Re: Communicating with my app via a socket
PostPosted: Sun Jan 27, 2013 9:06 pm 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
I would say that probably the easiest way to make your indexing app accessible over a socket would be to use a widely used data serialization format, RB supports XML and JSON so those would be good choices. Many, many other programming languages support one, the other or both of these formats, so if third-party clients are wanted, using one of these would make it much easier for the third parties.


As an example, here's a contrived JSON-based search protocol using a TCPSocket:
Dim sock As New TCPSocket
sock.Port = 50000
sock.Address = "127.0.0.1"
sock.Connect()
Dim query As New JSONItem
query.Value("Command") = "Search"
query.Value("Parameter") = "Ocarina"
Dim data As String = query.ToString
sock.Write(data + EndOfLine.Windows)


The other side of the TCPSocket (the indexer/server) would receive a string that looked like this:
Quote:
{"Command":"Search","Parameter":"Ocarina"}



The indexer/server would get the string and then convert it back into a JSONItem, determine how to respond, and then respond with another JSONItem:

Sub DataAvailable()
'In the TCPSocket's DataAvailable event
Dim data As String = Me.ReadAll

Dim query As New JSONItem(data)
If query.HasName("Command") Then
Select Case query.Value("Command").StringValue
Case "Search"
Dim result As JSONItem = SomeFunctionThatReturnsJSONResults(query.Value("Parameter"))
If result <> Nil Then
Dim response As New JSONItem
response.Value("Number of results") = result.Count
response.Value("Original Query") = query.Value("Parameter")
response.Value("Results") = result
data = response.ToString
Me.Write(data + EndOfLine.Windows)
End If

Case "Add"
'etc.

Case "Delete"
'etc.

End Select
End If
End Sub


A successful "Search" command might be serialized to the socket something like this:

Quote:
{"Number of results":1,"Original Query":"Ocarina","Results":{"Title":"Ocarina of Time","Location":"C:\\ROMs\\OoT\\Oot.rom"}}


The client would receive this in its DataAvailable event, and handle it much like the server did, just handling the other side of the conversation.

_________________
Boredom Software


Last edited by charonn0 on Mon Jan 28, 2013 4:23 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Communicating with my app via a socket
PostPosted: Mon Jan 28, 2013 2:21 am 
Offline
User avatar

Joined: Wed Oct 05, 2005 1:21 pm
Posts: 515
Location: United Kingdom
charonn0: That is incredibly useful. Thank you ever so much! Gives me a good foundation to explore

_________________
Gorgeous REALbasic controls from Figa Software | My Flickr | My Blog
11" MacBook Air 1.8Ghz i7, 4GB RAM, OSX 10.8.2, RB 2012 r1.1 Pro | iPhone 4S 32GB | Nikon D60


Top
 Profile  
Reply with quote  
 Post subject: Re: Communicating with my app via a socket
PostPosted: Mon Jan 28, 2013 5:48 am 
Offline
User avatar

Joined: Sun Oct 28, 2012 4:54 am
Posts: 264
Location: Herts, UK
:)

charonn0 that is very neat I like it

_________________
Real Studio 2012 R2
SysInfo
BackTrack Linux/BackBox Linux/Debian Lenny/Windows 7/Windows 8/OpenWRT/OpenBSD
& Yes it's me in the Avatar


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group