📄 simpleclient.java
字号:
import java.net.*;
import java.io.*;
public class SimpleClient
{
public static void main(String args[]) throws IOException
{
int c;
Socket s1;
InputStream s1_In;
DataInputStream din_s1;
OutputStream s1_out;
DataOutputStream dout_s1;
BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
s1 = new Socket(InetAddress.getLocalHost(),5432);
String s1_recv = new String("");
String s1_send = new String("");
s1_out = s1.getOutputStream();
dout_s1 = new DataOutputStream(s1_out);
s1_In = s1.getInputStream();
din_s1 = new DataInputStream(s1_In);
while(!s1_send.equals("Bye") && !s1_recv.equals("Bye"))
{
try
{
s1_out = s1.getOutputStream();
dout_s1 = new DataOutputStream(s1_out);
s1_send = b.readLine();
dout_s1.writeUTF(s1_send);
s1_In = s1.getInputStream();
din_s1 = new DataInputStream(s1_In);
s1_recv = din_s1.readUTF();
System.out.println("Server: " + s1_recv);
}
catch(IOException e)
{
System.out.println("exception caught");
}
}
din_s1.close();
dout_s1.close();
s1.close();
s1_In.close();
s1_out.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -