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.