import java.net.*;
import java.io.*;
public class Myclient implements Runnable 
{
	Socket clientSocket;
	boolean flag=true;
	Thread connenThread;
	BufferedReader cin;
	DataOutputStream cout;
	public static void main(String[] args)
	{
		
		new Myclient().clientStart();
		
	}
	public void clientStart()
	{
		try 
		{
			clientSocket = new Socket("localhost",8080);
			System.out.println("已建立连接");
			while(flag)
			{
				InputStream is = clientSocket.getInputStream();
				cin = new BufferedReader(new InputStreamReader(is));
				OutputStream  os= clientSocket.getOutputStream();
				cout = new DataOutputStream(os);
				connenThread = new Thread(this);
				connenThread.start();
				String aLine;
				
				while ((aLine = cin.readLine()) != null) 
				{
					System.out.println(aLine);
					if(aLine.equals("bye"))
					{
						flag=false;
						connenThread.interrupt();
						break;
						
						
					}
				}
				cout.close();
				os.close();
				cin.close();
				is.close();
				clientSocket.close();
				System.exit(0);
			}
		
		} 
		catch (Exception e) 
		{
			System.out.println(e);
		}
		
		
	
		
		
	}

	public void run() 
	{
		while(true)
		{
			try
			{
				int ch;
				while ((ch=System.in.read())!=-1) 
				{
					cout.write((byte)ch);
					if(ch=='\n')
					{
						cout.flush();
					}
				}
				
			}
			catch(Exception e)
			{
				System.out.println(e);
			}
			
		}
	}
	
	
	
}
最近下载更多
as501226107  LV12 2022年12月28日
丶知北游丿  LV9 2022年6月15日
bearloadprogress  LV7 2022年5月12日
tangjj7260  LV18 2021年12月10日
Super Gino  LV1 2021年11月8日
爱情戴罪的羔羊  LV7 2021年7月12日
飞翔的面包片  LV12 2021年7月12日
2673747024  LV7 2021年1月9日
liangge2115  LV27 2021年1月1日
yangctz  LV24 2020年11月25日
最近浏览更多
xiaokang1  LV9 3月29日
youwuzuichen  LV10 2023年12月15日
2290995171 2023年3月14日
暂无贡献等级
好好学代码 2023年2月16日
暂无贡献等级
aixiao5213  LV1 2022年12月28日
zhiwei0127  LV1 2022年11月6日
linboss  LV4 2022年8月18日
ewan007  LV29 2022年6月27日
106sadadwd  LV2 2022年6月18日
丶知北游丿  LV9 2022年6月15日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友