服务器和日志文件 [英] Server and Log File

查看:60
本文介绍了服务器和日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

我正在使用Java开发客户端/服务器应用程序。我通过java.net包创建了一个客户端和一个服务器

。但是现在我希望客户端登录到服务器时,会创建一个日志文件。


为此我创建了另一个只用于从cilent socket读取数据的类并且在这个类中实现了runnable。


现在这个读类被称为SocketReader,编码如下:


import java .io。*;

import java.net。*;


公共类socketReader实现Runnable {


BufferedReader readMessage;

String message ="" ;;


synchronized String socketReader(套接字客户端){

线程t =新线程(此);

t.start();


public void run(){

试试{



// while(true){

readMessage = new BufferedReader(new InputStreamReader

(client.getInputStream()));

message = readMessage.readLine();

readMessage.close();

//}

}

catch(IOException ioex){

System.out.println(" Exception:" + ioex);

}

} // run()在这里结束

返回消息;

} //构造函数在这里结束

} //类结束于此


问题是它给出了错误消息。

Wats出错了。我甚至试图在构造函数之外声明run()。

请回复

Hi there
I am developing a client/server app in Java. I have created a client and a server
via the java.net package. But now i want that ach time the client logs on to the server, a log file is created.

For this i created another class that is used only to read data from the cilent socket and implemented runnable in this class.

Now this reading class is called "SocketReader", and is coded as follows:

import java.io.*;
import java.net.*;

public class socketReader implements Runnable{

BufferedReader readMessage;
String message="";

synchronized String socketReader(Socket client){
Thread t=new Thread(this);
t.start();

public void run(){
try{


//while(true){
readMessage=new BufferedReader(new InputStreamReader
(client.getInputStream()));
message=readMessage.readLine();
readMessage.close();
//}
}
catch (IOException ioex){
System.out.println("Exception: "+ioex);
}
} // run () ends here
return message;
} // constructor ends here
} // class ends here

The problem is that it gives an error message.
Wats going wrong. i''ve even tried to declare the run() outside the constructor.
Kindly reply

推荐答案


您好

我正在使用Java开发客户端/服务器应用程序。我通过java.net包创建了一个客户端和一个服务器

。但是现在我希望客户端登录到服务器时,会创建一个日志文件。


为此我创建了另一个只用于从cilent socket读取数据的类并且在这个类中实现了runnable。


现在这个读类被称为SocketReader,编码如下:


import java .io。*;

import java.net。*;


公共类socketReader实现Runnable {


BufferedReader readMessage;

String message ="" ;;


synchronized String socketReader(套接字客户端){

线程t =新线程(此);

t.start();


public void run(){

试试{



// while(true){

readMessage = new BufferedReader(new InputStreamReader

(client.getInputStream()));

message = readMessage.readLine();

readMessage.close();

//}

}

catch(IOException ioex){

System.out.println(" Exception:" + ioex);

}

} // run()在这里结束

返回消息;

} //构造函数在这里结束

} //类结束于此


问题是它给出了错误消息。

Wats出错了。我甚至试图在构造函数外面声明run()。

请回复
Hi there
I am developing a client/server app in Java. I have created a client and a server
via the java.net package. But now i want that ach time the client logs on to the server, a log file is created.

For this i created another class that is used only to read data from the cilent socket and implemented runnable in this class.

Now this reading class is called "SocketReader", and is coded as follows:

import java.io.*;
import java.net.*;

public class socketReader implements Runnable{

BufferedReader readMessage;
String message="";

synchronized String socketReader(Socket client){
Thread t=new Thread(this);
t.start();

public void run(){
try{


//while(true){
readMessage=new BufferedReader(new InputStreamReader
(client.getInputStream()));
message=readMessage.readLine();
readMessage.close();
//}
}
catch (IOException ioex){
System.out.println("Exception: "+ioex);
}
} // run () ends here
return message;
} // constructor ends here
} // class ends here

The problem is that it gives an error message.
Wats going wrong. i''ve even tried to declare the run() outside the constructor.
Kindly reply



下次发布时请使用代码标签代码。

不要将run方法放在构造函数中。

如果在构造函数外部使用run方法,会得到什么错误消息?

Please use code tags next time when posting code.
Do not put the run method inside the constructor.
What error message do you get when you have the run method outside the constructor?



下次发布代码时请使用代码标签。

不要将run方法放在构造函数中。

如果在构造函数外部使用run方法,会得到什么错误消息?
Please use code tags next time when posting code.
Do not put the run method inside the constructor.
What error message do you get when you have the run method outside the constructor?



感谢您的回复!!

我收到的错误信息是:

非法表达开始在public void run()中。它指向公众。

Thanks for replying!!
The error msg that i recieve is that:
illegal start of expression in public void run(). It points on the public.



感谢您的回复!!

我收到的错误消息是:

在public void run()中非法启动表达式。它指向公众。
Thanks for replying!!
The error msg that i recieve is that:
illegal start of expression in public void run(). It points on the public.



抱歉延迟,我已断开连接。发布在构造函数外部有run方法的代码


记住代码标记。

Sorry for the delay, I''d got disconnected. Post the code that you have that has the run method outside the constructor

Remember the code tags.


这篇关于服务器和日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆