25.02.2017 Views

java_tutorial

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Java<br />

}<br />

{<br />

System.out.println("Socket timed out!");<br />

break;<br />

}catch(IOException e)<br />

{<br />

e.printStackTrace();<br />

break;<br />

}<br />

}<br />

}<br />

public static void main(String [] args)<br />

{<br />

int port = Integer.parseInt(args[0]);<br />

try<br />

{<br />

Thread t = new GreetingServer(port);<br />

t.start();<br />

}catch(IOException e)<br />

{<br />

e.printStackTrace();<br />

}<br />

}<br />

Compile the client and the server and then start the server as follows:<br />

$ <strong>java</strong> GreetingServer 6066<br />

Waiting for client on port 6066...<br />

Check the client program as follows:<br />

$ <strong>java</strong> GreetingClient localhost 6066<br />

Connecting to localhost on port 6066<br />

Just connected to localhost/127.0.0.1:6066<br />

Server says Thank you for connecting to /127.0.0.1:6066<br />

Goodbye!<br />

479

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!