-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add support for running server on nodejs TCP * commonize server starting and client creating * create common Servers object with all possible variations of started servers
- Loading branch information
olme04
authored
Apr 14, 2022
1 parent
e3efddb
commit a09a2b5
Showing
48 changed files
with
1,038 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
# chat | ||
|
||
* api - shared chat API for both client and server | ||
* client - client API implementation as requests to RSocket with Protobuf serialization. Works on JVM(TCP/WS), JS(WS), | ||
Native(TCP). Tasks for running sample clients: | ||
* JVM: `run` | ||
* Native: `runDebugExecutableNative` / `runReleaseExecutableNative` | ||
* NodeJs: `jsNodeRun` | ||
* Browser: `jsBrowserRun` | ||
* server - server API implementation with storage in ordinary concurrent map and exposing it through RSocket with | ||
Protobuf serialization. Can be started on JVM(TCP+WS) and Native(TCP). Tasks for running sample servers: | ||
* JVM: `run` | ||
* Native: `runDebugExecutableNative` / `runReleaseExecutableNative` | ||
* client - client API implementation via requesting to RSocket with Protobuf serialization. | ||
Works on JVM(TCP/WS), Native(TCP/WS), NodeJS(WS/TCP), Browser(WS). | ||
Tasks for running clients: | ||
* JVM: `run` | ||
* Native: `runDebugExecutableNative` / `runReleaseExecutableNative` | ||
* NodeJs: `nodejsNodeRun` / `nodejsNodeDevelopmentRun` / `nodejsNodeProductionRun` | ||
* Browser: `browserBrowserRun` / `browserBrowserDevelopmentRun` / `browserBrowserProductionRun` | ||
* server - server API implementation with storage in concurrent map | ||
and exposing it through RSocket with Protobuf serialization. | ||
Can be started on JVM(TCP/WS), Native(TCP/WS), NodeJS(TCP). | ||
Tasks for running servers: | ||
* JVM: `run` | ||
* Native: `runDebugExecutableNative` / `runReleaseExecutableNative` | ||
* NodeJs: `jsNodeRun` / `jsNodeDevelopmentRun` / `jsNodeProductionRun` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2015-2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.rsocket.kotlin.samples.chat.api | ||
|
||
enum class TransportType { TCP, WS } | ||
|
||
data class ServerAddress(val port: Int, val type: TransportType) | ||
|
||
object Servers { | ||
object JVM { | ||
val TCP = ServerAddress(port = 8001, type = TransportType.TCP) | ||
val WS = ServerAddress(port = 8002, type = TransportType.WS) | ||
} | ||
|
||
object JS { | ||
val TCP = ServerAddress(port = 7001, type = TransportType.TCP) | ||
} | ||
|
||
object Native { | ||
val TCP = ServerAddress(port = 9001, type = TransportType.TCP) | ||
val WS = ServerAddress(port = 9002, type = TransportType.WS) | ||
} | ||
|
||
val WS = setOf( | ||
JVM.WS, | ||
Native.WS | ||
) | ||
val TCP = setOf( | ||
JVM.TCP, | ||
JS.TCP, | ||
Native.TCP | ||
) | ||
|
||
val ALL = WS + TCP | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2015-2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.rsocket.kotlin.samples.chat.client | ||
|
||
import io.rsocket.kotlin.samples.chat.api.* | ||
import kotlinx.coroutines.* | ||
|
||
suspend fun main() { | ||
coroutineScope { | ||
//only WS is supported on browser JS | ||
// native WS server is incompatible with js WS client | ||
(Servers.WS - Servers.Native.WS).forEach { | ||
val client = ApiClient(it, "Yuri") | ||
launch { | ||
client.use(it, "RSocket is awesome! (from browser)") | ||
} | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
samples/chat/client/src/browserMain/kotlin/clientTransport.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2015-2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.rsocket.kotlin.samples.chat.client | ||
|
||
import io.ktor.client.engine.js.* | ||
import io.rsocket.kotlin.samples.chat.api.* | ||
import io.rsocket.kotlin.transport.* | ||
import io.rsocket.kotlin.transport.ktor.websocket.client.* | ||
|
||
internal actual fun clientTransport( | ||
type: TransportType, | ||
host: String, | ||
port: Int | ||
): ClientTransport = when (type) { | ||
TransportType.TCP -> error("TCP is not supported") | ||
TransportType.WS -> WebSocketClientTransport(Js, host, port) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.