d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Question About Setting Up A Small Local Server
Add Reply New Topic New Poll
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Jul 2 2013 02:48pm
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();
   }

}
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Jul 2 2013 02:59pm
dev two separate applications. one for the server one for the client.

make the server listen on local host, and the client connect to local host.

nothing hard about it. everything else just uses standard IO functions.
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Jul 2 2013 03:12pm
Quote (AbDuCt @ Jul 2 2013 03:59pm)
dev two separate applications. one for the server one for the client.

make the server listen on local host, and the client connect to local host.

nothing hard about it. everything else just uses standard IO functions.


alright I will write two separate apps
Member
Posts: 2,478
Joined: Jan 4 2007
Gold: 7,545.00
Jul 3 2013 08:38am
Def use 2 separate apps. Pick a port that other apps won't use. (You can google which ones are common and stay away from them)
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll