NettyClient
parent
24e773aad9
commit
aa5f611a15
|
@ -1,12 +1,14 @@
|
||||||
package com.ljsd.network.client;
|
package com.ljsd.network.client;
|
||||||
|
|
||||||
import com.google.protobuf.*;
|
import com.google.protobuf.*;
|
||||||
|
import com.ljsd.jieling.netty.PackageConstant;
|
||||||
import com.ljsd.jieling.netty.cocdex.Tea;
|
import com.ljsd.jieling.netty.cocdex.Tea;
|
||||||
import io.netty.bootstrap.Bootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.EventLoopGroup;
|
import io.netty.channel.EventLoopGroup;
|
||||||
import io.netty.channel.nio.NioEventLoopGroup;
|
import io.netty.channel.nio.NioEventLoopGroup;
|
||||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||||
|
import io.netty.handler.codec.base64.Base64Encoder;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import rpc.protocols.*;
|
import rpc.protocols.*;
|
||||||
|
@ -38,15 +40,15 @@ public class NettyClient {
|
||||||
.handler(new NettyTCPClientInitializer());
|
.handler(new NettyTCPClientInitializer());
|
||||||
Channel ch = b.connect("api.gamegs.cn",8741).sync().channel();
|
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);
|
NettyTCPClientHandler handler = ch.pipeline().get(NettyTCPClientHandler.class);
|
||||||
while(true){
|
while(true){
|
||||||
// handler.sendRequest_jieling(bytes);
|
handler.sendRequest_jieling(bytes);
|
||||||
System.out.println(11111);
|
System.out.println(11111);
|
||||||
TimeUnit.SECONDS.sleep(3);
|
TimeUnit.SECONDS.sleep(3);
|
||||||
}
|
}
|
||||||
|
@ -303,23 +305,23 @@ public class NettyClient {
|
||||||
return PlayerInfoProto.WorkShopEquipCreateRequest.newBuilder().setEquipTid(equipTid).build();
|
return PlayerInfoProto.WorkShopEquipCreateRequest.newBuilder().setEquipTid(equipTid).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static byte[] wrappedBuffer(short gameId, byte[] content) {
|
public static byte[] wrappedBuffer(short gameId, byte[] content) {
|
||||||
// int length = PackageConstant.GAMEID_LEN+PackageConstant.CONTENT_LEN+content.length;
|
int length = PackageConstant.GAMEID_LEN+PackageConstant.CONTENT_LEN+content.length;
|
||||||
// byte[] bytes = new byte[length];
|
byte[] bytes = new byte[length];
|
||||||
// int pos = 0;
|
int pos = 0;
|
||||||
// Tea.shortToByte(bytes, pos, gameId);
|
Tea.shortToByte(bytes, pos, gameId);
|
||||||
// pos += PackageConstant.GAMEID_LEN;
|
pos += PackageConstant.GAMEID_LEN;
|
||||||
// Tea.intToByte(bytes, pos, content.length);
|
Tea.intToByte(bytes, pos, content.length);
|
||||||
// pos += PackageConstant.CONTENT_LEN;
|
pos += PackageConstant.CONTENT_LEN;
|
||||||
//
|
|
||||||
//
|
|
||||||
// if (content.length != 0) {
|
if (content.length != 0) {
|
||||||
// System.arraycopy(content, 0, bytes, pos, content.length);
|
System.arraycopy(content, 0, bytes, pos, content.length);
|
||||||
|
}
|
||||||
|
// if (backMessage.length != 0) {
|
||||||
|
// LOGGER.info("wrappedBuffer uid=>{} sendbyte=>{}", uid, bytes1.length);
|
||||||
// }
|
// }
|
||||||
//// if (backMessage.length != 0) {
|
return bytes;
|
||||||
//// LOGGER.info("wrappedBuffer uid=>{} sendbyte=>{}", uid, bytes1.length);
|
}
|
||||||
//// }
|
|
||||||
// return bytes;
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue