From de011eacbe2597d37c75c6af4624a93605232722 Mon Sep 17 00:00:00 2001 From: "Mr.Huang" <1123033157@qq.com> Date: Fri, 24 Nov 2017 09:11:41 +0800 Subject: [PATCH] delete code --- .../java/com/dream/socket/DreamTCPSocket.java | 4 +- src/test/java/com/dream/socket/TCPClient.java | 127 ++---------------- 2 files changed, 13 insertions(+), 118 deletions(-) diff --git a/src/main/java/com/dream/socket/DreamTCPSocket.java b/src/main/java/com/dream/socket/DreamTCPSocket.java index de36c5e..1db56c5 100644 --- a/src/main/java/com/dream/socket/DreamTCPSocket.java +++ b/src/main/java/com/dream/socket/DreamTCPSocket.java @@ -63,7 +63,7 @@ protected boolean onStart() { LoggerFactory.getLogger().error("连接失败!"); } } catch (Exception e) { - LoggerFactory.getLogger().error("重连发生异常", e); + LoggerFactory.getLogger().error("连接异常", e); } finally { try { mSocket = null; @@ -74,7 +74,7 @@ protected boolean onStart() { LoggerFactory.getLogger().info("开始重连 -> " + mAddress.toString()); } } catch (Exception ie) { - LoggerFactory.getLogger().error("重连发生异常", ie); + LoggerFactory.getLogger().error("wait异常", ie); } } } diff --git a/src/test/java/com/dream/socket/TCPClient.java b/src/test/java/com/dream/socket/TCPClient.java index 185caf5..19bc44d 100644 --- a/src/test/java/com/dream/socket/TCPClient.java +++ b/src/test/java/com/dream/socket/TCPClient.java @@ -30,7 +30,17 @@ protected StringMessage decode(SocketAddress address, ByteBuffer buffer) { }, new MessageHandle() { @Override public void onStatus(int status) { - + switch (status){ + case Status.STATUS_CONNECTED: + System.out.println("socket connected"); + break; + case Status.STATUS_DISCONNECT: + System.out.println("socket disconnect"); + break; + case Status.STATUS_FAIL: + System.out.println("socket fail"); + break; + } } @Override @@ -44,120 +54,5 @@ public void encode(StringMessage data, ByteBuffer buffer) { } }); socket.start(); - -// StringBuilder writer = new StringBuilder(); -// writer.append("GET / HTTP/1.1\r\n"); -// writer.append("Host: www.oschina.net\r\n"); -// writer.append("Accept-Language: zh-cn\r\n"); -// writer.append("Connection: Keep-Alive\r\n"); -// writer.append("\r\n"); -// socket.send(writer.toString()); -// } -// -// public void setSocket(DreamTCPSocket socket) { -// this.socket = socket; -// } -// -// private Decode decode; -// private Encode encode; -// -// public Decode getDecode() { -// if (decode != null) { -// return decode; -// } -// return decode = new Decode() { -// @Override -// public Packet decode(ByteBuffer buffer) { -// int limit = buffer.limit(); -// if (limit < Protocol.HEADER_LENGTH) { -// return null; -// } -// char start = (char) buffer.get(); -// byte version = buffer.get(); -// int length = buffer.getInt();//包的总长度 包括头 -// buffer.get(Protocol.RETAIN); -// char xy = (char) buffer.get(); -// if (limit < length) { -// return null; -// } -// byte[] bytes = new byte[length - Protocol.HEADER_LENGTH]; -// buffer.get(bytes); -// char end = (char) buffer.get(); -// return new Packet(bytes); -// } -// }; -// } -// -// public Encode getEncode() { -// if (encode != null) { -// return encode; -// } -// return encode = new Encode() { -// @Override -// public void encode(Packet packet, ByteBuffer buffer) { -// buffer.put(Protocol.START_TAG); -// buffer.put(Protocol.VERSION); -// buffer.putInt(packet.body.length + Protocol.HEADER_LENGTH); -// buffer.put(Protocol.RETAIN); -// buffer.put(Protocol.VERIFY_TAG); -// buffer.put(packet.body); -// buffer.put(Protocol.END_TAG); -// } -// }; -// } -// -// public void onStatus(int status) { -// if (status == Handle.STATUS_CONNECTED) { -// socket.send(login()); -// } -// } -// -// public void onMessage(Packet data) { -// try { -// Protobuf.Body body = Protobuf.Body.parseFrom(data.body); -// switch (body.getType()) { -// case Type.BODY_ACK: -// System.out.println("onMessage: type=ack id=" + body.getId()); -// break; -// case Type.BODY_MESSAGE: -// Protobuf.Message message = Protobuf.Message.parseFrom(body.getContent()); -// System.out.println("onMessage: type=message id=" + body.getId() + " message=" + message.getContent().toStringUtf8()); -// socket.send(message("我已收到消息 id=" + body.getId())); -// break; -// case Type.BODY_LOGIN: -// Protobuf.Response response = Protobuf.Response.parseFrom(body.getContent()); -// System.out.println("onMessage: 登陆响应: " + response.getData().toStringUtf8()); -// break; -// default: -// break; -// } -// -// } catch (Exception e) { -// e.printStackTrace(); -// } -// -// } -// -// private Packet packet(int type, ByteString content) { -// Protobuf.Body body = Protobuf.Body.newBuilder() -// .setId(String.valueOf(System.currentTimeMillis())) -// .setSender(1) -// .setType(type) -// .setContent(content).build(); -// return new Packet(body.toByteArray()); -// } -// -// private Packet login() { -// Protobuf.Login login = Protobuf.Login.newBuilder().setToke("toke1").build(); -// return packet(Type.BODY_LOGIN, login.toByteString()); -// } -// -// private Packet message(String text) { -// Protobuf.Message message = Protobuf.Message.newBuilder() -// .setReceiver(101) -// .setType(Type.MESSAGE_SINGLE) -// .setContent(ByteString.copyFromUtf8(text)).build(); -// return packet(Type.BODY_MESSAGE, message.toByteString()); -// } }