Skip to content

Commit

Permalink
delete code
Browse files Browse the repository at this point in the history
  • Loading branch information
Sopage committed Nov 24, 2017
1 parent ba8aa4f commit de011ea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 118 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/dream/socket/DreamTCPSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -74,7 +74,7 @@ protected boolean onStart() {
LoggerFactory.getLogger().info("开始重连 -> " + mAddress.toString());
}
} catch (Exception ie) {
LoggerFactory.getLogger().error("重连发生异常", ie);
LoggerFactory.getLogger().error("wait异常", ie);
}
}
}
Expand Down
127 changes: 11 additions & 116 deletions src/test/java/com/dream/socket/TCPClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@ protected StringMessage decode(SocketAddress address, ByteBuffer buffer) {
}, new MessageHandle<StringMessage>() {
@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
Expand All @@ -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<Packet> decode;
// private Encode<Packet> encode;
//
// public Decode<Packet> getDecode() {
// if (decode != null) {
// return decode;
// }
// return decode = new Decode<Packet>() {
// @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<Packet> getEncode() {
// if (encode != null) {
// return encode;
// }
// return encode = new Encode<Packet>() {
// @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());
// }
}

0 comments on commit de011ea

Please sign in to comment.