Service side: Java jdk1.5 (using tools: eclipse3.2)
Client: Flex 2
(i) connection
Purpose: To achieve flex and Java connectivity
Service-side code: Server1.java
===============================================================================
import java.net.*;
import java.io.*;
public class Server1 {
public static void main(String[] args) {
ServerSocket server=null;
try{
server=new ServerSocket(8888);
//x1
System.out.println("服务器套接字已经被创建");
while(true){
System.out.println("等待客户机");
Socket newSocket=server.accept(); //x2
System.out.println("已与客户机连接");
}
}catch(IOException ie)
{
System.out.println(ie);
}finally{
Try
{
if(server!=null) server.close(); //x3
}catch(IOException ie){}
}
}
}
Knowledge Points:
X1: A server socket object was created with the specified port number.
X2: Calls the Accept () method to wait for the client's connection request.
X3: Closes the server socket. If no client machine has ever made a connection request, the server socket will continue to wait.
Run after compiling as shown: