Guest User

sampleConnection

a guest
Mar 5th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. Thread tt = new Thread()
  2.         {
  3.             @Override
  4.             public void run()
  5.             {
  6.             sock = new Socket();
  7.             InetAddress add = null;
  8.             try {
  9.                 add = InetAddress.getByName("1.2.3.4");
  10.             } catch (UnknownHostException e) {
  11.                 e.printStackTrace();
  12.             }
  13.            
  14.             InetSocketAddress j = null;
  15.             j = new InetSocketAddress(add, 5555);
  16.            
  17.             try {
  18.                 sock.setKeepAlive(true);
  19.                 sock.setReuseAddress(true);
  20.                 sock.setTcpNoDelay(true);
  21.                 sock.connect(j, 5000);
  22.             } catch (IOException e) {
  23.                
  24.                 e.printStackTrace();
  25.             }
  26.             InputStream iS = null;
  27.             try {
  28.                 iS = sock.getInputStream();
  29.             } catch (IOException e) {
  30.                 // TODO Auto-generated catch block
  31.                 e.printStackTrace();
  32.             }
  33.            
  34.             try {
  35.                 int res = iS.read();
  36.                 Log.e("THIS", "Read bytes = " + res);
  37.             } catch (IOException e) {
  38.                 // TODO Auto-generated catch block
  39.                 e.printStackTrace();
  40.             }
  41.             }
  42.         };
  43.                
  44.         tt.start();
Advertisement
Add Comment
Please, Sign In to add comment