Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
TCPConnectionListener.java
Package: SIP-applet-phone.zip [view]
Upload User: liulanlin
Upload Date: 2017-12-08
Package Size: 1274k
Code Size: 2k
Category:
VOIP program
Development Platform:
Java
- /*
- * TCPConnectionListener.java
- *
- * Created on November 19, 2003, 10:38 AM
- */
- package gov.nist.applet.phone.media.protocol.transport;
- import java.net.ServerSocket;
- import java.net.Socket;
- /**
- * This class is a thread waiting for connection on this TCP port and ip address
- * As soon as it gets a connection it notifies the Adapter for RTP.
- * @author DERUELLE Jean
- */
- public class TCPConnectionListener implements Runnable {
- private ServerSocket serverSocket;
- private Socket socket;
- //private TCPReceiveAdapter adapter;
- private Thread listener;
- private boolean ctrl;
- private boolean connected;
- /** Creates a new instance of TCPConnectionListener.
- * @param serverSocket - ServerSocket that will be waiting for connection.
- * @param adapter - the TCP Adapter for RTP we have to notify that we get a new connection.
- * @param ctrl - boolean to know if it's RTP connection (false) or a RTCP connection (true).
- */
- public TCPConnectionListener(ServerSocket serverSocket, boolean ctrl) {
- this.serverSocket=serverSocket;
- //this.adapter=adapter;
- this.ctrl=ctrl;
- connected=false;
- }
- /**
- * Start the listener thread.
- */
- public void start(){
- if(listener==null){
- listener=new Thread(this);
- listener.setName("TCPConnectionListener Thread");
- }
- listener.start();
- }
- /**
- * Task of the listener thread.
- */
- public void run() {
- try{
- socket=serverSocket.accept();
- System.out.println("Socket from "+ socket.getInetAddress() +
- " connected to the port "+socket.getLocalPort()+
- " control : "+ctrl);
- //adapter.setRemoteSocket(socket,ctrl);
- connected=true;
- listener=null;
- }
- catch(java.io.IOException ioe){
- ioe.printStackTrace();
- }
- }
- /**
- * Tells if this listener for TCP Connection has received a connection
- * @return the socket when the listener has received a new connection
- */
- public Socket waitForConnections(){
- while(!connected){
- try{
- Thread.sleep(1);
- }
- catch(InterruptedException ie){
- ie.printStackTrace();
- }
- }
- return socket;
- }
- }