BufferedReader br=new BufferedReader(new InputStreamReader(in));
while((temp=br.readLine())!=null)
{
System.out.println("receive client message :"+ temp);
if(!temp.equals(""))
{
String divide[]=temp.split("/");
Sql log =new Sql();
if(log.Logo(divide[0], divide[1])==1)
{
OutputStream out=socket.getOutputStream();
PrintWriter pw=new PrintWriter(out,true);
pw.println("1");
log.update_Ip(string_ip,divide[0]);
}
}
}请问我这样写为什么不能像客户端写入“1”呢??
while((temp=br.readLine())!=null)
{
System.out.println("receive client message :"+ temp);
if(!temp.equals(""))
{
String divide[]=temp.split("/");
Sql log =new Sql();
if(log.Logo(divide[0], divide[1])==1)
{
OutputStream out=socket.getOutputStream();
PrintWriter pw=new PrintWriter(out,true);
pw.println("1");
log.update_Ip(string_ip,divide[0]);
}
}
}请问我这样写为什么不能像客户端写入“1”呢??
解决方案 »
- 带安全策略文件的程序如何用installanywhere打包
- 链表 输出类信息错误 请大家帮忙
- jbuilder中小程序出问题
- 我是刚刚学习JAVA的,请高手指点该怎么学最有效率?
- 求正则表达式,谢谢
- MY_MY关于包的使用问题.我在CSDN上看了一天了,也不知道怎么会事!大侠们帮忙改一下!!!!!!
- 大家帮我看看这个程序那里的毛病,很简单的程序??
- 做IT的就应该进来看看,成立我们的IT工会
- 如何在jcreator中加入环境变量(class path)?
- [图文教程]Nutch教程——导入Nutch工程,执行完整爬取 by 逼格DATA
- Plurk API 範例不能執行
- 什么是适配器模式,我觉得与工厂模式有点相同。
import java.io.IOException;
import java.io.*;
import java.io.OutputStream;import java.net.*;
import java.io.DataOutputStream;import java.io.InputStream;
import java.util.LinkedList;
import java.util.List;public class EchoServer {
private int isOk;
private ServerSocket ss = null;
class ReceiveThread extends Thread {
private Socket socket = null;
public ReceiveThread(Socket socket) {
super("ReceiveThread");
this.socket = socket;
}
public void run() {
InputStream in = null;
while (true) { try {
in = socket.getInputStream();
InetAddress ip=socket.getInetAddress();
String string_ip=ip.toString().substring(1);
String temp;
System.out.println("连接ip"+ip);
BufferedReader br=new BufferedReader(new InputStreamReader(in));
while((temp=br.readLine())!=null)
{
System.out.println("receive client message :"+ temp);
if(!temp.equals(""))
{
OutputStream out = socket.getOutputStream();
PrintWriter pw=new PrintWriter(out,true);
pw.println("1");
String divide[]=temp.split("/");
Sql log =new Sql();
if(log.Logo(divide[0], divide[1])==1)
{
log.update_Ip(string_ip,divide[0]);
}
}
}
} catch (IOException e) {
try {socket.close();
in.close();
//dis.close();
} catch (IOException e1) {
e1.printStackTrace();
}
e.printStackTrace();
}
} }
}
public void send(Socket socket) throws IOException {
} public class AcceptSocketThread extends Thread {
public AcceptSocketThread() {
super("AcceptSocketThread");
}
public void run() {
try {
ss = new ServerSocket(6000); while (true) {
Socket socket = ss.accept();
new ReceiveThread(socket).start();
}
} catch (IOException e) {
e.printStackTrace();
try{
ss.close();
}
catch(IOException e2)
{}
} }
} public void start() {
new AcceptSocketThread().start();
}
}还是把全部代码贴出来吧!!
客户端没问题,关键是服务器的问题。OutputStream out = socket.getOutputStream();
PrintWriter pw=new PrintWriter(out,true);
pw.println("1");
这段代码已经是执行了,但是客户端收不到
PrintWriter pw=new PrintWriter(out,true);
pw.println("1");移动到WHILE的前面就能收到呢??