Recent Posts
None | 6 sec ago
PHP | 30 sec ago
None | 39 sec ago
PHP | 49 sec ago
C++ | 55 sec ago
None | 1 min ago
ActionScript 3 | 1 min ago
None | 1 min ago
None | 2 min ago
None | 2 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By TCPClientjava on the 15th of Sep 2008 11:14:44 AM Download | Raw | Embed | Report
  1. import java.io.*;
  2.  
  3. import java.net.*;
  4.  
  5. public class TCPClient{
  6.         public static void main(String argv[]) throws Exception{
  7.                 int port = 6789;  //default
  8.                     if (argv.length > 0) port = Integer.parseInt(argv[0]);
  9.                 BufferedReader inFromUser = new BufferedReader(
  10.                         new InputStreamReader(System.in));
  11.                 // To server on local host
  12.                 Socket clientSocket = new Socket("127.0.0.1", port);
  13.                 // To server on other host with IP-address = 83.92.58.109
  14.                 //Socket clientSocket = new Socket("83.92.58.109", port);
  15.                 PrintStream outToServer = new PrintStream(
  16.                         clientSocket.getOutputStream());
  17.                 BufferedReader inFromServer = new BufferedReader(
  18.                         new InputStreamReader(clientSocket.getInputStream()));
  19.                 String sentence = inFromUser.readLine();
  20.                 outToServer.println(sentence);
  21.                 String modifiedSentence = inFromServer.readLine();
  22.                 System.out.println("FROM SERVER: " + modifiedSentence);
  23.                 clientSocket.close();
  24.    }
  25. }
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: