我有使用套接字的客户端/服务器程序。 在服务器侧我有如何在java中减少套接字连接时间?
ServerSocket s=new ServerSocket(8888);
s.setSoTimeout(10000);
Socket incoming=s.accept();
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
ObjectInputStream ios = new ObjectInputStream(s.getInputStream());
s.close();
oos.close();
ios.close();
incoming.close();
在客户端我有
Socket s=new Socket("172.17.20.47", 8888);
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
ObjectInputStream ios = new ObjectInputStream(s.getInputStream());
s.close();
oos.close();
ios.close();
当我测量像的时间:
long start= System.CurrentTimeMillis();
Socket incoming=s.accept();
long end= System.CurrentTimeMillis();
System.out.println(end-start);
我表明Socket incoming=s.accept();
花费〜450ms。 我该如何缩短这个时间?因为所有代码的其余部分需要大约15ms。计算机之间
平是< 1ms的
'accept()'被阻塞,直到发出请求。所以你的时间测量不准确。 –