Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Socket Problem: Server for Web-Browser-Client

Reply
Thread Tools

Socket Problem: Server for Web-Browser-Client

 
 
dietmar
Guest
Posts: n/a
 
      10-07-2005
my server programm sends a response (e.g. HTML-code) to the requested
web-browser-client (firefox or IE).
It works, but only when the request data in the input-stream from the
client-socket are read.

Why??

Dietmar

see the example code:
....
ServerSocket server = new ServerSocket(80); // any other port(9991);
Socket client=server.accept();

String ip=client.getInetAddress().toString();

// Read request from client-socket input-stream
// if the entire read code is marked out as commentar,
// it doesn't worked.
InputStream is = client.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
StringBuffer request= new StringBuffer();
while ((r=br.readLine()).length()!=0)
{
request.append(r + "\n");
}

// Write response to client
OutputStream os = client.getOutputStream();
Date date=new Date();
String s= "<html> <head><title>Hallo Web</title></head>"+
"<body><h1>HELLO" + ip + " im WEB</h1>"+"</body>";
byte b[]=s.getBytes();
os.write(b);
....

IE-call: http:\\localhost


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 1 02-03-2009 06:20 AM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 0 02-01-2009 12:45 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 0 02-01-2009 07:37 AM
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57