package sock
;
import java
.io
.*
;
import java
.net
.ServerSocket
;
import java
.net
.Socket
;
public class MySock3 {
public static void main(String
[] args
) throws Exception
{
BufferedReader bufferedReader
= new BufferedReader(new InputStreamReader(System
.in
));
Socket socket
= new Socket("127.0.0.1", 12313);
BufferedWriter bufferedWriter
= new BufferedWriter(new OutputStreamWriter(socket
.getOutputStream()));
BufferedReader bufferedReader1
= new BufferedReader(new InputStreamReader(socket
.getInputStream()));
String line
= null
;
String s
;
while ((line
= bufferedReader
.readLine()) != null
) {
if ("end".equals(line
)) {
break;
}
bufferedWriter
.write(line
);
bufferedWriter
.newLine();
bufferedWriter
.flush();
s
= bufferedReader1
.readLine();
System
.out
.println("收到"+s
);
}
}
}
class MySer3{
public static void main(String
[] args
) throws Exception
{
ServerSocket serverSocket
= new ServerSocket(12313);
Socket socket
= serverSocket
.accept();
BufferedReader bufferedReader1
= new BufferedReader(new InputStreamReader(socket
.getInputStream()));
PrintWriter printWriter
= new PrintWriter(socket
.getOutputStream(),true);
String line
=null
;
while ((line
= bufferedReader1
.readLine()) != null
) {
System
.out
.println("line = " + line
);
printWriter
.println(line
);
}
socket
.close();
serverSocket
.close();
}
}
可以利用不同的io操作。