Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/ydp/net/YDPSocket.java


1   package org.ydp.net;
2   
3   import java.io.*;
4   import java.net.*;
5   
6   class YDPSocket
7   {
8       public static void main(String[] args)
9       {
10    String outstr = new String("scheidch\n");
11      
12    try
13    {
14        /* create a new socket */
15        Socket sock = new Socket("localhost", 23);
16        System.out.println("Created new socket");
17        
18        /* send HTTP GET request */
19        //try
20        //{
21      /* get a stream from the socket to write to */
22      //BufferedOutputStream ostream = new BufferedOutputStream(sock.getOutputStream(), 8192);
23      //System.out.println("Created BufferedOutputStream from socket");
24  
25      //ostream.write(outstr.getBytes());
26      //System.out.println("Wrote to socket");
27      //ostream.flush();
28      //ostream.close();
29      //ostream = null;
30        //}
31        
32        //catch(IOException e)
33        //{
34      //System.out.println("(1) Error: " + e);
35        //}
36        
37        boolean more = true;
38  
39        /* get a stream from the socket to read from */
40        DataInputStream istream = new DataInputStream(new BufferedInputStream(sock.getInputStream()));
41        System.out.println("Created DataInputStream from socket");
42        
43        while(more)
44        {
45      System.out.println("Reading data from socket");
46      String str = istream.readLine();
47      
48      if(str == null)
49      {
50          more = false;
51      }
52      
53      else
54      {
55          System.out.println(str);
56      }
57        }
58    }
59    
60    catch(IOException e)
61    {
62        System.out.println("(2) Error: " + e);
63    }
64      }
65  }