hmm, there are still some problems, its not closing the connection to the client for some reason. Client is just hanging.
how can I fix this problem?
Thanks!
server = new ServerSocket(8104)
while(true) {
server.accept() { socket ->
socket.withStreams { input, output ->
def s = new Socket("localhost", 9090)
s.withStreams{ ois, oos ->
oos << input
output << ois
}
}
}
}
From: viklund_anders@hotmail.com
To: user@groovy.codehaus.org
Date: Thu, 11 Mar 2010 23:13:30 +0000
Subject: RE: [groovy-user] HTTP Post/Get
This is now working, but how can I print the input/output streams or transform them into strings?
server = new ServerSocket(8890)
while(true) {
server.accept() { socket ->
socket.withStreams { input, output ->
def s = new Socket("localhost", 9090)
def result
s.withStreams{ ois, oos ->
oos << args
output << ois
}
s.close()
}
}
}
From: viklund_anders@hotmail.com
To: user@groovy.codehaus.org
Date: Thu, 11 Mar 2010 20:52:50 +0000
Subject: RE: [groovy-user] HTTP Post/Get
And if I would like to create a http proxy, just like
tcpmon , how to forward the request if the server looks something like this?
I would like to grab the input/output, but its just returning an integer instead of a string as it supposed to do.
server = new ServerSocket(5000)
while(true) {
server.accept() { socket ->
socket.withStreams { input, output ->
def s = new Socket("localhost", 8080)
s.withStreams{ ois, oos ->
oos << args
result = ois.read()
}
s.close()
output.withWriter { writer ->
writer << result
}
}
}
}
From: tim.yates@gmail.com
Date: Thu, 11 Mar 2010 20:12:32 +0000
To: user@groovy.codehaus.org
Subject: Re: [groovy-user] HTTP Post/Get
Posting the form on
http://www.snee.com/xml/crud/posttest.html with the http-builder package would look something like this:
@Grab( 'org.codehaus.groovy.modules.http-builder:http-builder:0.5.0-RC2' )
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.URLENC
def http = new HTTPBuilder( 'http://www.snee.com/xml/crud/' )
http.post( path:'posttest.cgi',
body:[ fname:'Tim' , lname:'Yates' ],
requestContentType:URLENC ) { resp, reader ->
println "Response status: ${resp.statusLine}"
System.out << reader
}
That posts the 2 fields on that page, then prints the results
Not used http-builder before though, so there may be a neater way of doing it :-)
Tim
Your E-mail and More On-the-Go. Get Windows Live Hotmail Free.
Sign up now.
Hotmail: Trusted email with powerful SPAM protection.
Sign up now.
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
Sign up now.