packagesockerk;
importjava.io.DataInputStream;
importjava.io.IOException;
importjava.net.Socket;
importjava.net.UnknownHostException;
publicclassSocketClient{
publicstaticvoidmain(String[]args){
Socketsocket=null;
try{
socket=newSocket("127.0.0.1"??8888);
DataInputStreamdis=newDataInputStream(socket.getInputStream());
Stringstring="";
while(!"end".equals(string)){
string=dis.readUTF();
System.out.println(string);
}
socket.close();
}catch(UnknownHostExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}catch(IOExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
}

?????????

packagesocket;
importjava.io.BufferedReader;
importjava.io.DataOutputStream;
importjava.io.IOException;
importjava.io.InputStreamReader;
importjava.net.ServerSocket;
importjava.net.Socket;
publicclassSocketSingleServer{
publicstaticvoidmain(String[]args)throwsIOException{
ServerSocketserverSocket=null;
Socketclient=null;
try{
serverSocket=newServerSocket(8888);
client=serverSocket.accept();
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
DataOutputStreamdos=newDataOutputStream(client.getOutputStream());
while(!client.isClosed()){
Stringstr="";
if((str=br.readLine())!=null){
dos.writeUTF(str);
dos.flush();
}
}
}catch(IOExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}finally{
client.close();
}
}
}
 ?????????