Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

ServerSocket.accept() problem

Thread view: 
christian.kleegrewe@siemens.com - 26 Mar 2007 09:35 GMT
Hi all,

I try to write a HTTP proxy using java.net.ServerSocket class, but I
do not understand the behaviour of the accept call.

Here is the part of the code where the ServerSocket is created and
accept is called.

-->
           ServerSocket s = new ServerSocket (localport);
           while (true) {
               Socket c = null;
               try {
                   display("listening...");
                   c = s.accept();
                   if (c != null) {
                       byte r_in[] = new byte[256];
                       String request = new String();
                       InputStream in = c.getInputStream();

-->

I am testing the code with an opera web browser that has configured my
own proxy as web proxy. What happens no is a little bit confusing. The
server starts correctly and "listening..." is pronted on the console
but when I type in an URL in the address bar and press enter nothing
happens. After terminating the request by pressing the X button in the
navigation bar the accept returns and the URL is retrieved by the
proxy but not transmitted to the web browser since there is no
connection any more after the X button has been pressed.

Is there anybody who can help me with this behaviour? As far as I
suppose the accept should return immediately after I typed in the URL
and pressed the load or go button.

I am using windows XP SP2 as operating system and java 1.507 as jdk

thanks in advance Christian
Gordon Beaton - 26 Mar 2007 09:46 GMT
> I am testing the code with an opera web browser that has configured my
> own proxy as web proxy. What happens no is a little bit confusing. The
[quoted text clipped - 4 lines]
> proxy but not transmitted to the web browser since there is no
> connection any more after the X button has been pressed.

Most likely your problem is not in accept() but in the part of the
code you didn't post, where you actually read the request from the
InputStream. Presumably you're reading to EOF instead of just to the
end of the request header, or something along those lines.

Try connecting with telnet instead of a web browser, and typing the
request manually so you have better control over the situation.

Try displaying each line as it's read by your server to see what's
happening.

/gordon

--


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.