Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java app receiving post data

Status
Not open for further replies.

harmmeijer

Programmer
Mar 1, 2001
869
CN
My questions are the comments in the sample code:

The code from burrowing through firewalls tells you how to use a socket on the server side and let the client listen to a Bufferreader (using URL)
The example tells me I should use post and the Keep-Alive of the connection
Well here is the applet code that POST's getNextMsg=true&uniqNum=" + uniqNum++
My problem is how do read this in the server:
here are the applet and server code snippets, (the things I edited)
the complete code is here:

applet:
URL baseUrl;
baseUrl = new URL(" + host + ":" + port + "/" );



URL u = new URL (baseUrl, encode ("getNextMsg " + uniqNum++));
URLConnection connU = u.openConnection();
connU.setDoOutput(true);
PrintWriter out = new PrintWriter(
connU.getOutputStream());
out.println("getNextMsg=true&uniqNum=" + uniqNum++);
BufferedReader in = new BufferedReader(
new InputStreamReader(
connU.getInputStream()));
strFromServer = in.readLine ();
in.close ();

server:
...
if (!str.endsWith(" HTTP/1.1")) {
...

ServerSocket ss = null;
ss = new ServerSocket(port);
Socket s = null;
s = ss.accept();
DataInputStream in =
new DataInputStream(new BufferedInputStream
(s.getInputStream()));
String str;
StringBuffer stbReadAll = new StringBuffer();


// how do I know when to stop reading the request.
while((str = in.readLine())!=null){
System.out.println("received line: " + str);
stbReadAll.append(str);
}
str = stbReadAll.toString();
//str shows me where the request came from
//now how do I read the submitted values!!!


This is what the output from the server:
C:\jdk1.3.1\bin\code\chaT>java SimpleChatServer
Ready...
waiting to accept
Accept
received line: POST /getNextMsg%206 HTTP/1.1
received line: Accept-Language: en
received line: Content-type: application/x-received line: Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
received line: User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Win32)
received line: Host: localhost:6006
received line: Content-Length: 0
received line: Connection: Keep-Alive
received line: Cache-Control: no-cache
received line:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top