- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
试图测试与我的 ws 的连接,但服务器看不到任何连接。
我想我错过了什么,你能告诉我我错过了什么吗?
日志:
D/Connection$connect:应该连接
D/Connection$connect: WaitingToRetry
D/Connection$connect:在 WebSocket 连接失败时
D/Connection$connect:应该连接
D/Connection$connect: WaitingToRetry
D/Connection$connect:在 WebSocket 连接失败时
有我的代码:
在 MainActivity
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Connection.connect()
}
object Connection {
fun connect() {
val okHttpClient = OkHttpClient.Builder()
.readTimeout(0, TimeUnit.MILLISECONDS)
.build()
val protocol = OkHttpWebSocket(
okHttpClient,
OkHttpWebSocket.SimpleRequestFactory(
{ Request.Builder().url("ws://someURL").build() },
{ ShutdownReason.GRACEFUL }
)
)
val configuration = Scarlet.Configuration(
streamAdapterFactories = listOf(RxJava2StreamAdapterFactory())
)
val scarletInstance = Scarlet(protocol, configuration)
val webSocketService = scarletInstance.create<WebSocketService>()
webSocketService.observeStateTransition()
.observeOn(Schedulers.io())
.subscribe({ stateTransition ->
val event = stateTransition.event
val description = when (event) {
is Event.OnLifecycleStateChange -> when (event.lifecycleState) {
LifecycleState.Started -> Timber.d("On Lifecycle Start")
LifecycleState.Stopped -> Timber.d("On Lifecycle Stop")
LifecycleState.Completed -> Timber.d("On Lifecycle Terminate")
}
is Event.OnProtocolEvent -> {
when (stateTransition.toState) {
is State.WillConnect -> Timber.d("WaitingToRetry")
is State.Connecting -> Timber.d("Connecting")
is State.Connected -> Timber.d("Connected")
is State.Disconnecting -> Timber.d("Disconnecting")
State.Disconnected -> Timber.d("Disconnected")
State.Destroyed -> Timber.d("Destroyed")
}
}
Event.OnShouldConnect -> Timber.d("Should Connect")
}
}, {
e ->
Timber.e(e)
})
webSocketService.observeWebSocketEvent()
.observeOn(Schedulers.io())
.subscribe({
event ->
val description = when(event){
is WebSocketEvent.OnConnectionOpened -> Timber.d("On WebSocket Connection Opened")
is WebSocketEvent.OnMessageReceived -> Timber.d("On WebSocket NewMessageUpdate Received")
is WebSocketEvent.OnConnectionClosing -> Timber.d("On WebSocket Connection Closing")
is WebSocketEvent.OnConnectionClosed -> Timber.d("On WebSocket Connection Closed")
is WebSocketEvent.OnConnectionFailed -> Timber.d("On WebSocket Connection Failed")
}
},
{
Timber.e(it)
})
}
}
interface WebSocketService {
@Receive
fun observeStateTransition(): Flowable<StateTransition>
@Receive
fun observeWebSocketEvent(): Flowable<WebSocketEvent>
}
最佳答案
您实际上可以通过添加 android:usesCleartextTraffic="true"
将 Scarlet 与 WS://一起使用。到您的 list 文件。
关于android - 无法使用 Tinder Scarlet 连接到 ws,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57675908/
为了获得 websocket 模块,我安装了这两个依赖项: implementation 'com.tinder.scarlet:scarlet:0.1.9' implementation "co
所以我最近使用scarlet WebSocket成功地将数据发送到我的在线服务器,但问题是我应该从服务器获得响应,但没有得到任何东西。下面是我的代码: class MainActivity : App
试图测试与我的 ws 的连接,但服务器看不到任何连接。 我想我错过了什么,你能告诉我我错过了什么吗? 日志: D/Connection$connect:应该连接 D/Connection$connec
来自 README.md 的代码 val scarletInstance = Scarlet.Builder() .webSocketFactory(okHttpClient.newWebS
我是一名优秀的程序员,十分优秀!