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

📄 client.java

📁 TCP Connection using java
💻 JAVA
字号:
import java.net.*;
import java.io.*;


class client{
Socket so;
public client(String host,int port) throws IOException
{
	try
	{
		so = new Socket(host, port);
	}
	catch (IOException e) { }
}
public void go()
{
	System.out.println("before try");
	if (so != null)
	{
		try
		{
			echange(so.getInputStream(), so.getOutputStream());
		}
		catch (IOException e)
		{
			System.err.println("Erreur " + e);
		}
	}
}
public void stop()
{
try{
	if (so != null)
so.close();
}
catch(IOException e){}
}
public void echange(InputStream is,OutputStream os) throws IOException
{
DataInputStream dis=new DataInputStream(is);
String tmp = dis.readUTF();
System.out.println(tmp);
DataOutputStream dos = new DataOutputStream(os);
dos.writeUTF(tmp);
}
public static void main(String argc[])
{
	try{
client c = new client("localhost",3000);
c.go();
c.stop();
	}
	catch(IOException e){}
}
}

⌨️ 快捷键说明

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