Browse Source

增加socket操作代码

dart3_last
fff 4 months ago
parent
commit
726e1d3055
  1. 14
      lib/im/SocketClient.dart

14
lib/im/SocketClient.dart

@ -41,6 +41,9 @@ class SocketClient {
} }
authRequest(String token) { authRequest(String token) {
if (!checkSocket()) {
return;
}
final authReq = AuthReq() final authReq = AuthReq()
..uid = 1 ..uid = 1
..token = '123456'; ..token = '123456';
@ -51,10 +54,21 @@ class SocketClient {
} }
sendMessage(var to, String content) { sendMessage(var to, String content) {
if (!checkSocket()) {
return;
}
Uint8List data = utf8.encode(content); Uint8List data = utf8.encode(content);
MsgData msgData = MsgData(to: to,from: 2,type: MsgType.SINGLE_TEXT,data: data); MsgData msgData = MsgData(to: to,from: 2,type: MsgType.SINGLE_TEXT,data: data);
final proto2 = Proto(5,1,msgData.writeToBuffer()); final proto2 = Proto(5,1,msgData.writeToBuffer());
_socket.add(proto2.toBytes()); _socket.add(proto2.toBytes());
} }
checkSocket() {
if (_socket == null) {
connect();
return false;
}
return true;
}
} }
Loading…
Cancel
Save