I have looked around and found different ways of doing this, all of which seem to generate an error. Here is what I am trying to run. It's connecting to a server which is already running. Any ideas on how to get this to work or change it so it does work?
String serverAddress = MainActivity.serverAddress;
int port = MainActivity.newport;
Socket socket = new Socket(serverAddress, port);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out = new PrintWriter(socket.getOutputStream(), true);
String getName=MainActivity.name;
// Process all messages from server, according to the protocol.
while (true) {
String line = in.readLine();
if (line.startsWith("SUBMITNAME")) {
out.println(getName);
}
else if (line.startsWith("NAMEACCEPTED")) {
//textField.setEditable(true);
}
else if (line.startsWith("MESSAGE")) {
mt.append(line.substring(8) + "\n");
}
}