NettyClient

back_recharge
lvxinran 2021-05-23 18:07:36 +08:00
parent 24e773aad9
commit aa5f611a15
1 changed files with 25 additions and 23 deletions

View File

@ -1,12 +1,14 @@
package com.ljsd.network.client;
import com.google.protobuf.*;
import com.ljsd.jieling.netty.PackageConstant;
import com.ljsd.jieling.netty.cocdex.Tea;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.base64.Base64Encoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rpc.protocols.*;
@ -38,15 +40,15 @@ public class NettyClient {
.handler(new NettyTCPClientInitializer());
Channel ch = b.connect("api.gamegs.cn",8741).sync().channel();
// PlayerInfoProto.SignInRequest.Builder builder = PlayerInfoProto.SignInRequest.newBuilder().setDayIndex(1203);
PlayerInfoProto.SignInRequest.Builder builder = PlayerInfoProto.SignInRequest.newBuilder().setDayIndex(1203);
ChatProto.ChatUserV3 userFrom = ChatProto.ChatUserV3.newBuilder().build();
ChatProto.ChatV3 chat = ChatProto.ChatV3.newBuilder().setFrom(userFrom).build();
byte[] bytes = wrappedBuffer((short) 100, chat.toByteArray());
// ChatProto.ChatUserV3 userFrom = ChatProto.ChatUserV3.newBuilder().build();
// ChatProto.ChatV3 chat = ChatProto.ChatV3.newBuilder().setFrom(userFrom).build();
// byte[] bytes = wrappedBuffer((short) 100, chat.toByteArray());
;
NettyTCPClientHandler handler = ch.pipeline().get(NettyTCPClientHandler.class);
while(true){
// handler.sendRequest_jieling(bytes);
handler.sendRequest_jieling(bytes);
System.out.println(11111);
TimeUnit.SECONDS.sleep(3);
}
@ -303,23 +305,23 @@ public class NettyClient {
return PlayerInfoProto.WorkShopEquipCreateRequest.newBuilder().setEquipTid(equipTid).build();
}
// public static byte[] wrappedBuffer(short gameId, byte[] content) {
// int length = PackageConstant.GAMEID_LEN+PackageConstant.CONTENT_LEN+content.length;
// byte[] bytes = new byte[length];
// int pos = 0;
// Tea.shortToByte(bytes, pos, gameId);
// pos += PackageConstant.GAMEID_LEN;
// Tea.intToByte(bytes, pos, content.length);
// pos += PackageConstant.CONTENT_LEN;
//
//
// if (content.length != 0) {
// System.arraycopy(content, 0, bytes, pos, content.length);
public static byte[] wrappedBuffer(short gameId, byte[] content) {
int length = PackageConstant.GAMEID_LEN+PackageConstant.CONTENT_LEN+content.length;
byte[] bytes = new byte[length];
int pos = 0;
Tea.shortToByte(bytes, pos, gameId);
pos += PackageConstant.GAMEID_LEN;
Tea.intToByte(bytes, pos, content.length);
pos += PackageConstant.CONTENT_LEN;
if (content.length != 0) {
System.arraycopy(content, 0, bytes, pos, content.length);
}
// if (backMessage.length != 0) {
// LOGGER.info("wrappedBuffer uid=>{} sendbyte=>{}", uid, bytes1.length);
// }
//// if (backMessage.length != 0) {
//// LOGGER.info("wrappedBuffer uid=>{} sendbyte=>{}", uid, bytes1.length);
//// }
// return bytes;
// }
return bytes;
}
}