generated from justuser-31/code_projects_template
35 lines
814 B
Kotlin
35 lines
814 B
Kotlin
package org.client
|
|
|
|
import com.beust.klaxon.Klaxon
|
|
import org.server.Person
|
|
import java.io.BufferedReader
|
|
import java.io.InputStreamReader
|
|
import java.io.PrintWriter
|
|
import java.net.Socket
|
|
|
|
data class Person(
|
|
val name: String,
|
|
val age: Int,
|
|
val city: String
|
|
)
|
|
|
|
const val serverPort: Int = 12345
|
|
const val rawJson = """{
|
|
"name": "Иван Иванов",
|
|
"age": 25,
|
|
"city": "Москва"
|
|
}"""
|
|
val json = Klaxon().parse<Person>(rawJson)
|
|
|
|
fun main() {
|
|
val socket = Socket("localhost", serverPort)
|
|
val writer = PrintWriter(socket.getOutputStream(), true)
|
|
val reader = BufferedReader(InputStreamReader(socket.getInputStream()))
|
|
|
|
writer.println(Klaxon().toJsonString(json))
|
|
val response = reader.readLine()
|
|
println("Received from server: $response")
|
|
|
|
socket.close()
|
|
}
|