Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Visual J# / September 2004

Tip: Looking for answers? Try searching our database.

openConnection() different in java & J#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Raza - 08 Sep 2004 14:47 GMT
Following read function does not return in J#, while if
following code is written in java, read() returns
immediately.

It looks in J# read() expects end of html tag.
I want read to return immediately as it returns in Java
any clue??

URL url = new URL("http://localhost/filename");
           
URLConnection con = url.openConnection();
                       
                   
InputStream d = con.getInputStream();

int av  = d.available();
   
d.read();//This does not return until timeout
Lars-Inge T?nnessen [VJ# MVP] - 08 Sep 2004 17:56 GMT
Could you please make a complete example for us ?

I have written an example for you. This is working.

public class Class1
{
public Class1()
{

 // The .net way...
 System.Net.WebClient web = new System.Net.WebClient();
 System.IO.Stream stream = web.OpenRead( "http://localhost/filename" );
 System.IO.StreamReader reader = new System.IO.StreamReader( stream );
 String line = new String("");
 while ( (line = reader.ReadLine()) != null )
  System.Console.WriteLine( line );
 reader.Close();
 stream.Close();
 // _______________________________________________________

 // The java way...
 try
 {
  java.net.URL url2 = new java.net.URL( "http://localhost/filename" );
  java.io.BufferedReader BReader =
       new java.io.BufferedReader(
           new java.io.InputStreamReader( url2.openStream() ));
  String line2 = new String("");
  while ( (line2 = BReader.readLine()) != null )
   System.out.println( line2 );
  BReader.close();
 }
 catch ( Exception e )
 {
  e.printStackTrace();
 }
 // _____________________________________________________
}

/** @attribute System.STAThread() */
public static void main(String[] args)
{
 new Class1();
}
}

Regards,
Lars-Inge T?nnessen
Ahmad - 20 Sep 2004 17:34 GMT
thanks for reply Lars-Inge Tønnessen

Yes WebClient class of .NET works fine, Is it only way to
connect to HTTP server. Can't we use Java code as it is.

Regards
Ahmad Raza

>-----Original Message-----
>
[quoted text clipped - 17 lines]
>  stream.Close();
>  //
_______________________________________________________

>  // The java way...
>  try
[quoted text clipped - 12 lines]
>  }
>  //
_____________________________________________________
> }
>
[quoted text clipped - 9 lines]
>
>.
Lars-Inge T?nnessen [VJ# MVP] - 20 Sep 2004 18:24 GMT
Hi Ahmad,

Yes, you can use java source code in J#.  You can use both .net and java.

Please see my second example in the reply above (also included below in this
post). Please include a complete example if you want us to take a look at
your code.

public class Class1
{
public Class1()
{
 // The java way...
 try
 {

  java.net.URL url2 = new java.net.URL( "http://localhost/filename" );

  java.io.BufferedReader BReader =
       new java.io.BufferedReader(
           new java.io.InputStreamReader( url2.openStream() ));

  String line2 = new String("");

  while ( (line2 = BReader.readLine()) != null )
   System.out.println( line2 );

  BReader.close();

 }
 catch ( Exception e )
 {
  e.printStackTrace();
 }
}

/** @attribute System.STAThread() */
public static void main(String[] args)
{
 new Class1();
}
}

Regards,
Lars-Inge T?nnessen

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.