Always better to use SSL
# ktor
g
Always better to use SSL
o
Ok but how do i make a raw sockets server?
d
I would use websockets if possible
o
why websockets though?
g
Raw socket is very low level, and not sure that Ktor can provide anythin on top of raw socket
o
ok
d
you can use ktor with raw sockets, but not applications
I would use websockets for several reasons:
o
like?
d
- TCP raw sockets don’t have a notion of packets while websocket has - WebSockets allow using HTTP authentication, cookies and sessions.
It is futureproof, and would allow you to publish that game in HTML while raw sockets no
o
hmm
g
and don’t forget about encription, you need some protocol in case of tcp socket, websockets provide tls out of the box
d
if it helps, I created a small sample of a multiplayer game using ktor here: https://github.com/mmo-poc/mmo-poc
o
Also on a sidenote, are the SSL connections to a server from a app in ktor are fixed now?
d
do you mean connecting to a raw socket with SSL from ktor?
o
ooh thnx @Deactivated User
yeah
tht irc app
g
raw socket is not encrypted by default, you need some protocol for encryption
d
not sure, there were a lot of fixes, but not sure if that SSL specific issue is fixed, still for that case that wouldn’t be a client, but a server. And in that case, the SSL certificate is handled by the server. Netty for example. Or if you have an nginx reverse-proxying it, that nginx can work too. For example: http://ktor.io/quickstart/guides/ssl.html
o
hmm
m
Depending on your latency requirements, you may want to use UDP. Many action games use UDP to avoid TCP's unpredictable behavior in the face of latency
Commonly in games, you care more about getting current data tahn about getting every single change, in order, which is what TCP will give you.
However, if you do want TCP, which is stream oriented, you'll need some way of sending messages in a stream (since you're not just sending one big file), and therefore you'll need something like WebSockets or BEEP, and at that point might as well use WebSockets to get TLS.
There's also DTLS for UDP.
There is a certain irony in WebSockets -- we take a message oriented protocol (IP), build a stream protocol on top of it (TCP), then a message protocol (WS) on top of that, because frequently careless firewall deployments made TCP on HTTP's ports the only thing that worked...
Anyway, none of that is ktor specific, but hopefully gives you some idea of what you should be looking at
v
I would also consider grpc for that, I know this has nothing to do with ktor, but I have played around with the concept of a game server using ktor for web/websockets and web dashboards, but grpc used for client communication. And the bi directional streaming support was very nice, also you get protobuf "for free". You could send binary websocket of course, but with grpc you would not have to worry with serialization at least.
g
+1 for grpc. But for simple cases, like just requesting non realtime data by request, simple rest with Ktor should be also good
BTW you also can use protobuf with ktor