我最近了解了Java中的套接字,並通過套接字從客戶端向服務器來回發送信息。 我想實現的是從客戶端向服務器發送「用戶名」和「密碼」,然後根據數據庫中的數據檢查這些變量。通過套接字發送多個變量從客戶端到服務器
發送這兩個單獨的值到服務器的值,以便它可以驗證服務器端的最佳方式是什麼?
客戶端
clientSocket = new Socket("192.168.56.1", 7777);
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
out = new PrintWriter(clientSocket.getOutputStream(), true);
//starting the thread
while(runner == null)
{
runner = new Thread(this);
runner.start();
}
}
public void run()
{
String userNameAdminLogin;
String passwordAdminLogin;
while(runner == Thread.currentThread())
{
userNameAdminLogin = txtUserName.getText();
passwordAdminLogin = txtPassword.getText();
out.println(userNameAdminLogin);
out.println(passwordAdminLogin);
}
服務器側
while(listening)
{
clientSocket = ServerSoc.accept();
in = new DataInputStream(clientSocket.getInputStream());
BufferedReader is = new BufferedReader(new InputStreamReader(in));
os = new PrintStream(clientSocket.getOutputStream());
//How can I save the two seperate cases of data in variables on server side?
System.out.println(is.readLine());
}
親切的問候
阿里安