1. Establish a TCP/IP connection
The constructor socket (string host, int port) in the socket class is used to create a socket and connect to the specified host and port. Due to restrictions on the Java Applet security mechanism, the host name cannot be specified arbitrarily, but should be the same as the name of the host where the called applet is located. Therefore, the getcodebase method can first obtain the URL of the class file currently read by the browser, and then return the host name represented by a string from the URL through the gethost method. Example from http://person.zj.cninfo.net /~ In this URL, you can return the host name "person.zj.cninfo.net" represented by a string ".
The value of the standard port address is generally: SMTP is 25, POP3 is 110, FTP is 21, and so on. Of course, some hosts use non-standard ports, before using it, you 'd better confirm it first.
2. sending and receiving data
Use the getoutputstream method in the socket class to obtain the output data stream corresponding to the current socket. Use the writebytes method in the dataoutputstream class to write data to the output data stream one by one.
Use the getinputstream method in the socket class to obtain the input data stream corresponding to the current socket. Use the Readline method in the datainputstream class to read data from the input data stream row by row.
3. Disable TCP/IP connection
You can use the close method in the socket class to close the TCP/IP connection.