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

📄 nettalkclient.java

📁 java编写的聊天室
💻 JAVA
字号:
package com.java.NetTalk;


import java.io.IOException;
import java.net.Socket;
import java.net.InetAddress;
import java.util.Scanner;
import com.java.*;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;



public class NetTalkClient extends MyNet{
		public NetTalkClient(){
			
		}
		
		public NetTalkClient(String sHost,int port)throws IOException,ProtNetException{
			if(port < NetTalkClient.SYSTEM_PROT_MAXNUMBER)
				throw new ProtNetException("Prot error");
			socket = new Socket(sHost,port);
			socketChannel = socket.getChannel();
		}
		
		public void  SetContent(String sHost,int port)throws IOException,ProtNetException{
				if(port > NetTalkClient.SYSTEM_PROT_MAXNUMBER)
					throw new ProtNetException("Prot error");
				socket = new Socket(sHost,port);
				socketChannel = socket.getChannel();
		} 
		
		public NetTalkClient(InetAddress address, int port)throws IOException,ProtNetException{
			if(port > NetTalkClient.SYSTEM_PROT_MAXNUMBER)
				throw new ProtNetException("Prot error");
			socket = new Socket(address,port);
		}
		
		public void DisplayInfo(){
			
		}
		
		public int GetPort(){
				return socket.getPort();
		}
		
		public InetAddress GetConnectionAddress(){
				return socket.getInetAddress();
		}
		
		public boolean SendMessage(ByteBuffer message) throws IOException,NotOpenNetException{
				if(socketChannel.isOpen()){
					throw new NotOpenNetException("Not Open Channel");
				}
				socketChannel.write(message);
				return true;
		}
		
		public void CloseSocket() throws IOException{
				socket.close();
		} 
	
	private static final int SYSTEM_PROT_MAXNUMBER = 1024;
	private SocketChannel  socketChannel;
	private Socket socket;
}

⌨️ 快捷键说明

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