help with keeping client connected to server
My client wont stay connected to the server. I dont want to have to create a new connection every time i want it to perform something. I want it to connect once and stay connected.
heres my client code:
Code :
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
public class Client {
private DataInputStream in;
private DataOutputStream out;
private Socket server;
private String recived, sent;
public static void main(String[] args) {
Client c = new Client();
try {
c.Connect("127.0.0.1", 43594);
} catch (UnknownHostException e) {} catch (IOException e) {}
}
public void Connect(String IP, int PORT) throws UnknownHostException, IOException {
server = new Socket(IP, PORT);
in = new DataInputStream(server.getInputStream());
out = new DataOutputStream(server.getOutputStream());
if (!server.getKeepAlive()) {
server.setKeepAlive(true);
}
if (server.getKeepAlive()) {
out.writeUTF("Test");
recived = in.readUTF();
System.out.println(recived);
}
}
}
does setKeepAlive not keep the connection live?