I've decided to create the json messages my self so I can control the formatting.
"{\"command\": \"create_lobby\", \"status\" \"success\", \"lobby_id\": \"$id\"}"
I've been looking at the docs for chan but I can't figure out how to change this.
https://www.tcl.tk/man/tcl/TclCmd/chan.html
When I send a message from my tcl server to a python client the
message comes out in 3 lines and when I send a message to a java
client I have to read the channel 3 times as it reads the channel one
line at a time.
This is what I'm sending:
chan puts $channel [json::dict2json [dict create "time" "to" "say" "goodbye"]]
And this is what is received on both clients:
{"time": to
,"say": goodbye
}
What are the benefits of sending the data as base64?
The json would do the whole line then do another line with the ending bracket but I think I found a suitable solution. I haven't tested it fully as I am busy but it seems to work fine.
chan puts $channel {command: create_lobby, status: success, lobby_id: 1}
The whole message goes through as one line in java and then I turn it into a hash map by looping through it.
I'm making an online desktop application UNO game where there can be multiple lobbies, the server is running on a computer with open forward ports, the server handles input from the clients to do things like edit a database and then relay the newdatabase values to all the clients in that lobby such as deck size. I want to be able to send commands from the clients such as "create_lobby" and provide arguments with that command such as "lobby_name".
What would you suggest is the best protocol for that?
Shaun Kulesa <[email protected]> wrote:
I want to be able to send commands from the clients such as
"create_lobby" and provide arguments with that command such as
"lobby_name".
What would you suggest is the best protocol for that?
Take a look at the Tcllib 'comm' module.
It provides exactly this "send a command to a remote Tcl interpreter" functionality.
Shaun Kulesa <[email protected]> wrote:
What are the benefits of sending the data as base64?
The disadvantage is your messages grow by about 33% in size due to the encoding.
I want to be able to send commands from the clients such as
"create_lobby" and provide arguments with that command such as
"lobby_name".
What would you suggest is the best protocol for that?
On 4/13/2023 10:54 AM, Rich wrote:
Shaun Kulesa wrote:
I want to be able to send commands from the clients such as
"create_lobby" and provide arguments with that command such as
"lobby_name".
What would you suggest is the best protocol for that?
Take a look at the Tcllib 'comm' module.
It provides exactly this "send a command to a remote Tcl interpreter" functionality.I think the OP is already using at least two clients written in other languages: Python and Java. I am not sure comm will help much here as
the desire is to get a simple line-based text messaging protocol working.
* saitology9 <[email protected]>
| The only change you need, and my earlier suggestion should have
| included, is that you need to explicitly include a newline character
| after you do string map because we went from the issue of multiple
| lines to no lines at all. Then any simple client will read it fine.
Maybe I'm missing something, but [chan puts] already adds a newline
after the text, so why would another \n at the end of the text be required?
| % chan puts $channel "[string map {\n { }} [json::dict2json $data]]\n"
This blind replacement of \n by a space IMHO is a data-depending bug
waiting to happen (any \n in the actual payload will get lost).
No guessing what might be a suitable replacement for \n etc.
Whenever I need to send arbitrary data on a line oriented connection,
I encode it via base64 as one line per message:
No guessing what might be a suitable replacement for \n etc....
This blind replacement of \n by a space IMHO is a data-depending bug
waiting to happen (any \n in the actual payload will get lost).
On 4/13/2023 10:54 AM, Rich wrote:
Shaun Kulesa <[email protected]> wrote:
I want to be able to send commands from the clients such as
"create_lobby" and provide arguments with that command such as
"lobby_name".
What would you suggest is the best protocol for that?
Take a look at the Tcllib 'comm' module.
It provides exactly this "send a command to a remote Tcl interpreter"
functionality.
I think the OP is already using at least two clients written in other languages: Python and Java. I am not sure comm will help much here as
the desire is to get a simple line-based text messaging protocol working.
The
client side could be more thorough in that it can keep reading and
checking to see if it is a complete json document. However, this also
has flaws in that it fails to recognize when a bad json doc is sent.
I think it was rich who pointed out that the OP could switch to a
"message" oriented scheme or use something like http. That would work,
but it may not be worth the trouble given the task.
I'm making an online desktop application UNO game where there can be multiple lobbies, the server is running on a computer with open forward ports, the server handles input from the clients to do things like edit a database and then relay the newdatabase values to all the clients in that lobby such as deck size. I want to be able to send commands from the clients such as "create_lobby" and provide arguments with that command such as "lobby_name".
What would you suggest is the best protocol for that?
I'm making an online desktop application UNO game where there can be
multiple lobbies, the server is running on a computer with open forward ports, the server handles input from the clients to do things like edit a database and then relay the new database values to all the clients in
that lobby such as deck size. I want to be able to send commands from the clients such as "create_lobby" and provide arguments with that command
such as "lobby_name".
What would you suggest is the best protocol for that?
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 35:26:23 |
| Calls: | 12,109 |
| Files: | 15,006 |
| Messages: | 6,518,351 |