ExploitationJavaThe network capability provided by the. NET package. Take the connected stream communication method as an example,
The operations on the server are generally:
(1) create a serversocket object to listen to requests sent from the client on the specified port.
(2) When receiving a request, the accept () method returns a socket object.
(3) Use the preceding socket object to create input and output stream objects.
(4) interaction with customers through input and output streams.
When the listener completes interaction, the input and output streams and the socket are closed.
Butler serviceProgramThe operation ends. Disable serversocket.
ImplementationCodeCode class:
Try {
Boolean flag = true;
Socket clientsocket = NULL;
Serversocket = new serversocket (0 );
System. Out. println ("server listen on:" + serversocket. getlocalport ());
While (FLAG ){
Clientsocket = serversocket. Accept ();
Datainputstream is = new datainputstream (New bufferedinputstream (Client
Socket. getinputstream ()));
Printstream OS = new printstream (New bufferedoutputstream (clientsocket.
Getoutputstream ()));
// Process the applet request
OS. Close ();
Is. Close ();
Clientsocket. Close ();
}
Serversocket. Close ();
} Catch (ioexception e ){
System. Err. println ("exception:" + E );
}
The operations on the client are as follows:
(1) create a socket object to establish a connection with the server.
(2) Use this socket object to create input and output streams.
(3) interact with the server.
(4) After interaction, close the input and output streams and socket.
The implementation code class is as follows:
Try {
Socket clientsocket = new socket ("servername", 7 );
Outputstream OS = clientsocket. getoutputstream ();
Datainputstream is = new datainputstream (clientsocket. getinputstream ())
;
// Other operations.
OS. Close ();
Is. Close ();
Clientsocket. Close ();
} Catch (exception e ){
System. Err. println ("exception:" + E );
}
This method only relies on standard Java Network support and does not require additional software packages or tools,
Therefore, it is quite concise and flexible, and easy to implement some special needs.
From: http://www.javah.net/wangluobiancheng/20070605/2330.html