Ktor version: Choose the latest Ktor version.Ĭonfiguration in: Choose HOCON file to specify server parameters in a dedicated configuration file.Īdd sample code: Disable this option to skip adding sample code for plugins. Website: Leave the default value as a domain used to generate a package name.Īrtifact: This field shows a generated artifact name. Location: Specify a directory for your project.īuild System: Make sure that Gradle Kotlin is selected as a build system. On the right pane, specify the following settings: In the New Project wizard, choose Ktor from the list on the left. Otherwise, from the main menu, select File | New | Project. On the Welcome screen, click New Project. To create a base project for our application using the Ktor plugin, open IntelliJ IDEA and follow the steps below: Make sure the Ktor plugin is installed and enabled. If you use IntelliJ IDEA Community or other IDE, you can generate a Ktor project using a web-based project generator. Now that we have confidence in the technology we want to use for the implementation of our project, let's start with the set-up! Prerequisites All modern browsers can work with WebSockets out of the box, and frameworks to work with WebSockets exist in many programming languages and on many platforms. WebSockets are also a widely supported technology. Because Ktor provides high-level abstractions over the WebSocket protocol, we can even concentrate on text and binary frames, and leave the handling of other frames to the framework. We can think of frames as WebSocket messages which come in different types (text, binary, close, ping/pong). Unlike regular HTTP requests, WebSocket connections can be kept open for a long time and have an easy interface for exchanging data between the client and server in the form of frames. Chat sessions are also bidirectional – clients want to send chat messages, and see chat messages from others. Chat sessions are usually long-lived, with the client receiving messages from other participants over a long period of time. WebSockets are a great fit for applications like chats or simple games. Because Ktor is both a server-side and client-side framework, we will be able to reuse the knowledge we acquire building the chat server when it comes to building the client.Īfter completing this tutorial, you should have a basic understanding of how to work with WebSockets using Ktor, how to exchange information between the client and server, and get a basic idea of how to manage multiple connections at the same time. The client application will allow users to join a common chat server, send messages to other users, and see messages from other users in the terminal.įor both parts of the application, we will make use of Ktor's support for WebSockets. The chat client application will be implemented in this tutorial: Creating a WebSocket chat client. The chat server application will accept and manage connections from our chat users, receive messages, and distribute them to all connected clients. Throughout this tutorial, we will implement a simple chat service, which will consist of two applications: In this tutorial, you will learn how to create a simple chat application that uses WebSockets.
0 Comments
Leave a Reply. |