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

📄 client.java

📁 学生资料管理系统 基于c/s模式开发 用户可以运行用户端登陆服务器 然后通过客户端来进行服务器端的数据库操作
💻 JAVA
字号:
import java.io.*;
import java.net.*;


/**
 * author sunringove
 * data 2007-01-17
 * 该类用于客户端的数据处理 如 发送数据到服务器 从服务器接收数据
 */
public class Client {   
	
	private Socket socketConnection=null;
	private ObjectOutputStream clientOutputStream=null;
	private ObjectInputStream clientInputStream=null;
	public Member member[] = new Member[1024]; 
	public Member mem;
	public String string=new String();
		
	
	public Client() throws InterruptedException,  IOException{	
		
		try {         
					
				socketConnection = new Socket("172.26.51.250", 2785);    
				clientOutputStream = new ObjectOutputStream(socketConnection.getOutputStream());
				clientInputStream = new ObjectInputStream(socketConnection.getInputStream());
		} catch( Exception  e) {}
	}
	
	//************************************************************************************
	//发送一个字符串到服务器
	//************************************************************************************
	public void sendString(String string) throws IOException, ClassNotFoundException
	{
			clientOutputStream.writeObject(string); 
	}
	
	//************************************************************************************
	//发送一个对象数组到服务器
	//************************************************************************************
	public void sendObject(Member[] mem) throws IOException, ClassNotFoundException
	{
		clientOutputStream.writeObject(mem);
	}
	
	//************************************************************************************
	//发送一个对象到服务器
	//************************************************************************************
	public void sendObject(Member mem) throws IOException
	{
		clientOutputStream.writeObject(mem);
	}
	
	//	************************************************************************************
	//从服务器接收一个字符串
	//************************************************************************************
	public String receiveString() throws IOException, ClassNotFoundException
	{
		string = (String)clientInputStream.readObject();
		return string;
	}
	
	//************************************************************************************
	//从服务器接收对象数组
	//************************************************************************************
	public Member[] receiveObject() throws IOException, ClassNotFoundException
	{
		member = (Member[])clientInputStream.readObject();
		return member;
	}
	
	
	//************************************************************************************
	//从服务器接收一个对象
	//************************************************************************************
	public Member receiveSingleObject() throws IOException, ClassNotFoundException
	{
		mem = (Member)clientInputStream.readObject();
		return mem;
	}
	
	//************************************************************************************
	//关闭输入输出流
	//************************************************************************************
	public void closeStream(){
		try {
			clientOutputStream.close();
			clientInputStream.close();  
		} catch (IOException e) {
			e.printStackTrace();
		}  
				
	}
	
	/*
	public static void main(String args[]) throws IOException, ClassNotFoundException, InterruptedException{
		Client client = new Client();
		client.sendString("hello");
		System.out.println(client.receiveString());
		client.sendString("我是客户端");
		
		Member mem[]=new Member[1024];
		mem=client.receiveObject();
	
	}
		
		*/
        
                
           
		
	


} 

⌨️ 快捷键说明

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