client.java
来自「TCP Connection using java」· Java 代码 · 共 55 行
JAVA
55 行
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 + =
减小字号Ctrl + -
显示快捷键?