TCP-oriented protocols are more secure, similar to phone calls, but less efficient. Its basic model is request-respond. In here we use the things Java has encapsulated socket class ServerSocket and sockets
The former is the server, the latter is the client, this has a little different, the client's port is automatic acquisition do not need us like UDP also need us to specify, when the C, s to establish a connection between the two to establish a pipeline, the server output stream is the client's input stream.
For communication between the client and the server. The client is receiving data + sending data
1. Client:
public class Clients {public
static void Main (string[] args) throws Unknownhostexception, IOException {
//TODO A uto-generated method Stub
Socket client=new socket ("localhost", 5888);
Char[] Cbuf=new char[1024];
InputStreamReader in=new InputStreamReader (Client.getinputstream ());
In.read (CBUF);
System.out.println (string.valueof (CBUF));
}
2. Service-Side communication:
public class Servers {public static void main (String [] arg) throws ioexception{
Versocket server=new ServerSocket (5888);
Socket socket=server.accept ();
SYSTEM.OUT.PRINTLN ("Success");
BufferedWriter bf=new BufferedWriter (New OutputStreamWriter (Socket.getoutputstream ()));
Bf.write ("Wangjun");
Bf.flush (); }