Skip to content

Instantly share code, notes, and snippets.

@hydai
Created November 13, 2013 12:09
Show Gist options
  • Save hydai/7448067 to your computer and use it in GitHub Desktop.
Save hydai/7448067 to your computer and use it in GitHub Desktop.
class MyProgramB {
private int port=8000;
private DateInputStream in;
private DataOutputStream out;
private Socket socket;
public MyProgramB() throws Exception {
socket = new Socket("127.0.0.1");
// 建立與 "127.0.0.1" 的連線
in = new DataInputStream(socket.getInputStream());
// 建立一個 DataInputStream 來得到 server 的輸入
out = new DataOutputStream(socket.getOutputStream());
// 建立一個 DataOutputStream 以傳送資料給 server
out.writeDouble(40.00);
// 傳送 double value 40.00 給 server
System.out.println(in.readDouble());
// 在本地的 console 印出 server 傳送過來的 double value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment