Flex 动态页面显示

1 篇文章 0 订阅
 import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import org.asteriskjava.manager.AbstractManagerEventListener;
import org.asteriskjava.manager.AuthenticationFailedException;
import org.asteriskjava.manager.ManagerConnection;
import org.asteriskjava.manager.ManagerConnectionFactory;
import org.asteriskjava.manager.ManagerEventListener;
import org.asteriskjava.manager.TimeoutException;
import org.asteriskjava.manager.action.StatusAction;
import org.asteriskjava.manager.event.AgentCalledEvent;
import org.asteriskjava.manager.event.ManagerEvent;
import org.asteriskjava.manager.event.NewCallerIdEvent;
//public class freshEvent implements ManagerEventListener {
public class freshEvent  extends AbstractManagerEventListener{
private ManagerConnection managerConnection;
    private int port=9527;
    private String callerIdNum;
    private ServerSocket serverSocket;
    private Socket clientSocket = null;
    //private PrintWriter out;
    public freshEvent() throws IOException, IllegalStateException,
    AuthenticationFailedException, TimeoutException, InterruptedException
    {
        serverSocket = new ServerSocket(port);
        ManagerConnectionFactory factory = new ManagerConnectionFactory(
                "localhost", "admin", "amp111");
        this.managerConnection = factory.createManagerConnection();
  managerConnection.login();
        managerConnection.addEventListener(this);  
    }
 public void writeToSocket() throws IOException, IllegalStateException, AuthenticationFailedException, TimeoutException, InterruptedException
    {
     while(true)
     {
     try {
          System.out.println("ppp");
             clientSocket = serverSocket.accept();
             PrintWriter out= new PrintWriter(clientSocket.getOutputStream());
             out.println("Jsjsjsjsjjs"+"/0");
             out.flush();
             System.out.println("ffff");
         } catch (IOException e) {
             System.err.println("Accept failed.");
             System.exit(1);
         }
     }
    }
/*public void onManagerEvent(ManagerEvent event) {
  try{
  callerIdNum=((NewCallerIdEvent)event).getCallerId();
  PrintWriter out= new PrintWriter(clientSocket.getOutputStream());
        out.println(callerIdNum+"/0");
        out.flush();
        }catch(Exception e){e.printStackTrace();}
}*/
    protected void handleEvent(AgentCalledEvent event) {
        callerIdNum=event.getCallerId();
        try{
                PrintWriter out = new PrintWriter(clientSocket.getOutputStream());
                out.print(callerIdNum + "/0");
                out.flush();
                System.out.println("send ok");
        }catch(Exception e){
                e.printStackTrace();
   }
    }
    public static void main(String args[]) throws IOException, IllegalStateException,
    AuthenticationFailedException, TimeoutException, InterruptedException
    {
     freshEvent he=new freshEvent();
     he.writeToSocket();
    }
}
注释掉的是不能用的类(不能获得稳定实值)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值