Commit e3bbf3f0 authored by txp's avatar txp

服务端掉线,客户端等待

parent d040cfc8
......@@ -23,7 +23,7 @@ public class Client { //
InputStream is = null;
DataInputStream dis = null;
try {
s = new Socket(InetAddress.getByName("192.168.216.1"), 8888);
s = new Socket(InetAddress.getByName("192.168.3.3"), 8888);
/* 1.键盘录入账号和密码 */
sc = new Scanner(System.in);
System.out.println("账号:");
......
......@@ -6,6 +6,7 @@ public class Client {
System.out.println("发送第"+i+"次");
MySocketConnection.getSocket().getOutputStream().write(("发送第"+i+"次").getBytes("gbk"));
}catch(Exception e){
System.out.println("服务器已断开, 正在重连...");
MySocketConnection.socket = null;
sendMsg(i);
}
......
......@@ -10,7 +10,7 @@ public class Main {
i ++ ;
c.sendMsg(i);
try {
Thread.sleep(10000);
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
......
......@@ -13,7 +13,7 @@ public class MySocketConnection {
public static Socket getSocket(){
try {
if(socket == null){
return new Socket(InetAddress.getByName("192.168.216.1"),12345);
return new Socket(InetAddress.getByName("192.168.3.3"),8888);
}else{
return socket;
}
......
......@@ -9,7 +9,7 @@ import java.net.UnknownHostException;
public class Connect {
private static final ThreadLocal<Socket> threadConnect = new ThreadLocal<Socket>();
private static final String HOST = "192.168.216.1";
private static final String HOST = "192.168.3.3";
private static final int PORT = 8888;
......@@ -48,15 +48,15 @@ private static final ThreadLocal<Socket> threadConnect = new ThreadLocal<Socket>
private static class KeepThread implements Runnable {
public void run() {
try {
System.out.println("=====================开始发送心跳包==============");
System.out.println("========开始发送心跳包========");
int i = 0;
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("发送心跳数据包");
System.out.println("跳了" + i++ + "次");
outStr.write("send heart beat data package !".getBytes());
}
} catch (IOException e) {
......@@ -69,7 +69,7 @@ private static final ThreadLocal<Socket> threadConnect = new ThreadLocal<Socket>
private static class RecvThread implements Runnable {
public void run() {
try {
System.out.println("==============开始接收数据===============");
System.out.println("========开始接收数据========");
while (true) {
byte[] b = new byte[1024];
int r = inStr.read(b);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment