---------------------- <a href="http://edu.csdn.net"target="blank">ASP.Net+Android+IOS开发</a>、<a href="http://edu.csdn.net"target="blank">.Net培训</a>、期待与您交流! ----------------------
package com.itheima;
import java.net.*;import java.io.*;
public class TCPServer {
public static void main(String[] args)throws Exception{
ServerSocket ss=new ServerSocket(111);
while(true){
Socket sc=ss.accept();
DataInputStream dis=new DataInputStream(
sc.getInputStream());
System.out.println(dis.readUTF());
dis.close();
sc.close();
}
}
}
package com.itheima;
import java.net.*;
import java.io.*;
import java.util.*;
public class TCPClient {
public static void main(String[] args)throws Exception{
Socket sc=new Socket("127.0.0.1",111);
OutputStream os=sc.getOutputStream();
DataOutputStream dos=new DataOutputStream(os);
Scanner s=new Scanner(System.in);
System.out.println("请输入一串字符串:");
String st=s.nextLine();
dos.writeUTF(st);
dos.flush();
dos.close();
sc.close();
}
}
---------------------- <a href="http://edu.csdn.net"target="blank">ASP.Net+Android+IOS开发</a>、<a href="http://edu.csdn.net"target="blank">.Net培训</a>、期待与您交流! ----------------------