Flex and Java Socket Communication (i) connection

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.