I am wanting to test some stuff out and I need a small personal server I can abuse.
I am working in Java and I already have what appears to be a stupid simple client, but I need a personal server to just echo back stuff to me.
Wondering how I would go about that? I am pretty uneducated in anything server-client related atm, mostly doing this stuff on self research.
Would I have to write a small server program and run it and keep it running before I run the client?
Is there any possible to way to run the client and server off the same program? (Maybe on different threads or something)
basic tut worthy client -
Code
import java.io.*;
import java.net.*;
public class SocketLulz {
public static void main(String[] args) throws IOException {
Socket echo = null;
PrintWriter outbound = null;
BufferedReader inbound = null;
try {
echo = new Socket("", 7);
outbound = new PrintWriter(echo.getOutputStream(), true);
inbound = new BufferedReader(new InputStreamReader(echo.getInputStream()));
} catch (UnknownHostException e) {
System.err.println("Where da host at?!");
System.exit(1);
} catch (IOException e) {
System.out.println("I/O problemz yo");
System.exit(1);
}
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
String userin;
while ((userin = stdin.readLine()) != null) {
outbound.println(userin);
System.out.println("echo: " + inbound.readLine());
}
outbound.close();
inbound.close();
stdin.close();
echo.close();
}
}