⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientthread.java

📁 java编写的sip协议软电话,结构非常清晰的SIP协议栈
💻 JAVA
字号:
package JavaPhoneTeam10;

import java.io.*;
import java.net.*;

class ClientThread extends Thread {
	private Socket socket;
	private BufferedReader in;
	private PrintWriter out;
	private static int threadcount = 0;
	
	public ClientThread(InetAddress addr) {
		
		try {
			socket = new Socket(addr, PhoneServer.PORT);
		} 
		catch (IOException e) {
			System.err.println("Socket failed");
		}//end of catch
		
		try {
			in = new BufferedReader(
				   new InputStreamReader(
				   	 socket.getInputStream()));
			out = new PrintWriter(
				    new BufferedWriter(
				      new OutputStreamWriter(
				      	socket.getOutputStream())),true);
			start();
		} 
		catch(IOException e) {
			try {
				socket.close();
			} 
			catch(IOException e2) {
				System.err.println("Socket not closed");
			}
		}//end of catch(IOException e)
		//otherwise the socket will be closed by the run() method of the thread.
	}//end of JabberClientThread(InetAddress addr)
	
	public void run(){
		try {
			String str = in.readLine();
			System.out.println(str);
			out.println("END");
		} 
		catch(IOException e ) {
			System.err.println("Socket not closed");
		}
	}
}

public class ClientThread {
	public static void main(String[] args)
    throws IOException, InterruptedException {
	  	InetAddress addr = InetAddress.getByName(null);
	    while(true) {
	   	    new ClientThread(addr);
    	  	Thread.currentThread().sleep(1000);
	    }//end of while
	 }//end of main()
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -