/**********************************************************************
*$RCSfile:SkClient.java,v $ $Revision: 1.0 $ $Date:2018-3-12 $
*********************************************************************/
package org.ddl.nw;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
/**
* <li>Title: SkClient.java</li>
* <li>Description: 简介</li>
* <li>Project: JAVA_NET_DATA</li>
* <li>Copyright: Copyright (c) 2018</li>
*
* @Company: GXLU. All Rights Reserved.
* @author dudl Of VAS2.Dept
* @version 1.0
*/
public class SkClient implements Runnable {
private SkServer server;
private Socket currentSocket;
public SkClient(SkServer server, Socket socket) { // 从哪个server过来的
System.out.println("有新的socket");
this.server = server;
this.currentSocket = socket;
new Thread(this).start();
}
public void run() {
while (true) {
try {
BufferedReader bd = new BufferedReader(new InputStreamReader(
this.currentSocket.getInputStream()));
String result = "";
String content;
while ((content = bd.readLine()) != null) {
// 拿到结果了,去分派下去
for (Socket client : server.clients) {
if (client != this.currentSocket) {// 分派出去
// 返回结果
PrintWriter pw = new PrintWriter(client
.getOutputStream());// 向socket写入数据
pw.println(content);
pw.flush();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
/*******************************************************************************
* $RCSfile:SkClient.java,v $ $Revision: 1.0 $ $Date:2018-3-12 $
*
* $Log:SkClient.java,v $
******************************************************************************/
*$RCSfile:SkClient.java,v $ $Revision: 1.0 $ $Date:2018-3-12 $
*********************************************************************/
package org.ddl.nw;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
/**
* <li>Title: SkClient.java</li>
* <li>Description: 简介</li>
* <li>Project: JAVA_NET_DATA</li>
* <li>Copyright: Copyright (c) 2018</li>
*
* @Company: GXLU. All Rights Reserved.
* @author dudl Of VAS2.Dept
* @version 1.0
*/
public class SkClient implements Runnable {
private SkServer server;
private Socket currentSocket;
public SkClient(SkServer server, Socket socket) { // 从哪个server过来的
System.out.println("有新的socket");
this.server = server;
this.currentSocket = socket;
new Thread(this).start();
}
public void run() {
while (true) {
try {
BufferedReader bd = new BufferedReader(new InputStreamReader(
this.currentSocket.getInputStream()));
String result = "";
String content;
while ((content = bd.readLine()) != null) {
// 拿到结果了,去分派下去
for (Socket client : server.clients) {
if (client != this.currentSocket) {// 分派出去
// 返回结果
PrintWriter pw = new PrintWriter(client
.getOutputStream());// 向socket写入数据
pw.println(content);
pw.flush();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
/*******************************************************************************
* $RCSfile:SkClient.java,v $ $Revision: 1.0 $ $Date:2018-3-12 $
*
* $Log:SkClient.java,v $
******************************************************************************/