[求助]刚学的,请指点错误再哪?
我已经改了几个地方了 ,还是有问题。请指点了,谢谢!(服务器端程序)import java.io.*;
import java.net.*;
public class ServerTest
{ ServerTest()
{
try
{
boolean flag = true;
Socket links = null;
ServerSocket myServer=new ServerSocket(800);
System.out.println("Server listen on:"+myServer.getLocalPort());
while(flag)
{
links = myServer.accept();
FirstThread First =new FirstThread(links);
First.start();
SecondThread Second = new SecondThread(links);
Second.start();
}
}
catch (IOException e)
{
System.out.println("ServerException"+e);
}
}
public static void main(String[] args)
{
new ServerTest();
}
}
class FirstThread extends Thread //读入
{
Socket linkSocket;
String inputLine;
public FirstThread(Socket ls)
{
linkSocket = ls;
}
public void run()
{
try
{
DataInputStream dis = new DataInputStream(new BufferedInputStream(linkSocket.getInputStream()));
//获得从Client读入的数据流
inputLine = dis.readLine();//从Client读入信息
while(!inputLine.equals("Bye"))
{
System.out.println("Client端输入的信息为:"+inputLine);
inputLine = dis.readLine();
}
dis.close();
linkSocket.close();
}
catch (IOException e)
{
System.out.println("SeverException"+e);
}
}
}
class SecondThread extends Thread //输出
{ Socket linkSocket;
String line="";
public SecondThread(Socket ls)
{
linkSocket = ls;
}
public void run()
{
try
{
PrintWriter os = new PrintWriter(linkSocket.getOutputStream());
//获得向Client输出的数据流
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
os.println("Hello! Wellcome connect to myserver!");
os.flush();//向Client端输出信息
line = in.readLine();
while(!line.equals("Bye"))
{
os.println(line);
line = in.readLine();
}
os.close();
linkSocket.close();
}
catch (IOException e)
{
System.out.println("SeverException"+e);
}
}
}