关于socket:如何判断连接超时?
public class Server extends Thread
你应该在2022年开始加密货币投资吗? <
ServerSocket serverSocket;
public Server()
<
try
<
serverSocket=new ServerSocket(1001);
System.out.println(serverSocket.toString());
>
catch(IOException e)
<
fail("could not start server",e);
>
System.out.println("server srarted. ");
this.start();
>
public static void fail(String str,Exception err)
<
System.out.println(str+" . "+err);
System.exit(1);
>
public void run()
<
try
<
while(true)
<
Socket clientSocket=serverSocket.accept();
MyConnection con=new MyConnection(clientSocket);
>
>
catch(IOException 你应该在2022年开始加密货币投资吗? e)
<
fail("not listening",e);
>
public static void main(String args[])
<
new Server();
>
class MyConnection extends Thread
<
protected Socket netClient=null;
protected BufferedReader fromClient=null;
protected PrintStream toClient=null;
protected String login=null,password=null,fromMessage=null,toMessage=null;
protected Date date=new Date();
protected GregorianCalendar calendar=new GregorianCalendar();
protected RandomAccessFile logFile;
public MyConnection(Socket clientSocket)
<
netClient=clientSocket;
try
<
fromClient=new BufferedReader(new InputStreamReader(netClient.getInputStream()));
toClient=new PrintStream(netClient.getOutputStream());
logFile=new RandomAccessFile("log.txt","rw");
>
catch(IOException e)
<
try
<
netClient.close();
>
catch(IOException err)
<
System.err.println("Unable to set up stream "+err);
return;
>
>
this.start();
public void writeFile(String entry)
<
try
<
logFile.seek(logFile.length());
logFile.writeBytes(entry);
>
catch(IOException e)
<
System.out.println("can not write on to the log file"+e);
>
>
public boolean userLogin()
<
try
<
while(true)
<
toClient.println("Login:");
login=fromClient.readLine();
if (login==null)
<
toClient.println("error,user name can not be null,login again or enter exit quit talking");
continue;
>
else if(login.equals("exit"))
<
System.out.println("default user quiting. ");
return false;
>
else
<
while(true)
<
toClient.println("Password:");
password=fromClient.readLine();
if(password==null)
<
System.out.println("password error");
continue;
>
else
<
System.out.println(login+" logged in. ");
writeFile(login+" logged in. "+"\n");
calendar.setTime(date);
String strTime="on date "
+calendar.get(Calendar.YEAR)+"-"
+calendar.get(Calendar.MONTH)+"-"
+calendar.get(Calendar.DATE)+" "
+"at time "
+calendar.get(Calendar.HOUR)+":"
+calendar.get(Calendar.MINUTE)+":"
+calendar.get(Calendar.SECOND)+". ";
System.out.println(strTime);
writeFile(strTime+"\n");
System.out.println(login+"'s password is "+password);
writeFile(login+"'s password is "+password+"\n");
public void run()
try
<
boolean userlogin=userLogin();
BufferedReader stdin=new BufferedReader(new InputStreamReader((System.in)));
toMessage=": hi,"+login;
for(;userlogin;)
<
toClient.println("from zjyserver "+toMessage);
writeFile("from zjyserver "+toMessage+"\n");
String fromMessage=fromClient.readLine();
if(fromMessage.equals("exit"))
<
System.out.println(login+" exiting. ");
writeFile(login+" exiting. "你应该在2022年开始加密货币投资吗? +"\n");
break;
>
else
<
System.out.println("from "+login+" "+fromMessage);
writeFile("from "+login+" "+fromMessage+"\n");
toMessage=stdin.readLine();
calendar.setTime(date);
String strTime="at("
+calendar.get(Calendar.YEAR)+"-"
+calendar.get(Calendar.MONTH)+"-"
+calendar.get(Calendar.DATE)+" "
+calendar.get(Calendar.HOUR)+":"
+calendar.get(Calendar.MINUTE)+":"
+calendar.get(Calendar.SECOND)+"): ";
toMessage=strTime+toMessage;
>
>
Simple Sidebar
The starting state of the menu will appear collapsed on smaller screens, and will appear non-collapsed on larger screens. When toggled using the button below, the menu will change.
Make sure to keep all page content within the #page-content-wrapper . The top navbar is optional, and just for demonstration. Just create an element with the #sidebarToggle ID which will 你应该在2022年开始加密货币投资吗? toggle the menu when clicked.
你应该在2022年开始加密货币投资吗?
SpringBoot+Mybatis logback不打印SQL解决方案
最近项目,由于测试提出需要将日志按天滚动日志,所以用了logback,日志打印工具。 但是由于使用了mybatis-config.xml 一直不打印SQL。最后将 这行注释,并且在application.properties里添加 就可以了,以下是完整的配置。 mybatis-config.xml: logback相关: logback.xml: logback-prod.x.
The logback manual #03# Configuration
索引 Configuration in logback Automatically configuring logback Automatic configuration with logback-test.xml or logback.xml Automatic printing of status messages in case of warning or er.
【异常】ERROR in [email protected] :22 - no applicable action for [charset], current ElementPath is [[configuration][appender][encoder][charset]]
一、异常信息 二、原因分析 从异常信息no applicable action for [charset]可以看出,是因为charset标签不可用导致,可能是logback版本的原因。 我的配置是这样的,存在charset标签: 三、解决方案 将logback配置中,charset标签去掉就可以了 .
ERROR in [email protected] :41 - no applicable action for [AppenderRef], current ElementPath is [[Configuration][Loggers][Root][AppenderRef]]
1、错误原因 SpringBoot 引入 rocketmq-spring-boot-starter 报错 2、解决方案-排除依赖 项目成功启动 .
A potentially dangerous Request.Path value was detected from the client异常解决方案
场景: 当URL中存在“,*,%,&. /”特殊字符时,页面会抛出A potentially dangerous Request.Path value was detected from the client异常。 原因: 是ASP.NET默认的拦截机制,保证页面URL传输的一定安全性。 解决方案有两种: 第一种,直接.
Ceph 时钟偏移问题 clock skew detected 解决方案--- 部署内网NTP服务
告警:HEALTH_WARN clock 你应该在2022年开始加密货币投资吗? skew detected on mon.ip-10-25-195-6; 8 requests are blocked > 32 sec; Monitor clock skew detected 原因: MON可能被MON节点之间的重要的时钟偏移激烈的影响。这经常会转变为没有明显原因的诡异的行为。为了避免这种问题,你应该在M.
ORA-00060: Deadlock detected 模拟死锁产生与解决方案
死锁:死锁是指两个或两个以上的进程在执行过程中,由于竞争资源或者由于彼此通信而造成的一种阻塞的现象,若无外力作用,它们都将无法推进下去。此时称系统处于死锁状态或系统产生了死锁,这些永远在互相等待的进程称为死锁进程。 死锁产生的4个必要条件 产生死锁的必要条件: 互斥条件:进程要求对所分配的资源进行排它性控制,即在一段时间内某资源仅为一进程所占用。 请求和保持条件:当进程因请求资源而阻塞时,对已获得.
GHOST还原时错误An internal inconsistency has been detected..Internal Error 25002解决办法(-ntexact参数)
· GHOST还原时错误An internal inconsistency has been detected..25002解决办法(-ntexact参数) 错误提示:An 你应该在2022年开始加密货币投资吗? internal inconsistency has been detected, If this problem persists. ,点OK后出现 Internal Error 25002 字样。 错误截图.
Simple Sidebar
The starting state of the menu will appear collapsed on smaller screens, and will appear non-collapsed on larger screens. When toggled using the button below, the menu will change.
Make sure 你应该在2022年开始加密货币投资吗? to keep all page content within the #page-content-wrapper . The top navbar is optional, and just for demonstration. Just create an element with the #sidebarToggle ID which will toggle the menu when clicked.