groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric MacAdie <emaca...@gmail.com>
Subject Re: Help with socket programming and loops
Date Mon, 25 May 2015 18:54:52 GMT
Thanks, I'll try that.

But I don't know if it will work. Ultimately, I would like to make a mail
server. Trying to solve problems locally with the Groovy console seemed
like it would be more efficient.

I think that during the session, a client and server exchange messages on
the same socket until the message is delivered. So far I have been able to
send parts of an email from one server to another, and so far I got the
EHLO, MAIL and RCPT commands. But the MAIL command is multiple lines. This
is where I am having problems.

But I will try your suggestion.

= Eric MacAdie

On Mon, May 25, 2015 at 1:25 PM, Ralph Johnson <johnson@cs.uiuc.edu> wrote:

> Do you close the socket?  Usually hasNext is only false on a socket when
> the socket is closed.
>
> On Mon, May 25, 2015 at 10:48 AM, Eric MacAdie <emacadie@gmail.com> wrote:
>
>> Hello Groovy users.
>>
>> I am trying to do some socket programming in Groovy. I am using code
>> found here as a template:
>>
>> http://programmingitch.blogspot.com/2010/04/groovy-sockets-example.html
>>
>> My problem is with the server code.
>>
>> It reads in the input buffer from a reader using the reader.readLine()
>> method. It turns out it's a BufferedReader.
>>
>> A problem that I am having is: What if the input is more than one line?
>>
>> I have been trying for a few hours to get this.
>>
>> Neither reader.getText(), reader.readLines() nor reader.eachLine() worked.
>>
>> I tried a few things like this:
>> def reader = input.newReader()
>>             def cc = reader.eachLine {
>>                 println "Here is the next element: ${it}"
>>             }
>>             println "Done iterating"
>>
>> and
>>             def reader = input.newReader()
>>             def iter = reader.iterator()
>>             while ( iter.hasNext() ) {
>>                 println "Here is the next element: ${iter.next()}"
>>                 println "About to get next, do we have next? "
>>                 println "iter is a ${iter?.getClass()?.getName()}"
>>             }
>>             println "Done iterating"
>>
>> and
>>            def holdLine
>>             while ( ( holdLine = reader.readLine() ) ) {
>>                 println "holdLine: ${holdLine}"
>>
>>             }
>>             println "Done"
>>
>> In each case, it reads each line, but it does not get to the line after
>> the loop.
>>
>> Maybe there is something obvious that I am missing and I am making a
>> mistake only a noob would make, but why won't the code break out of the
>> loop?
>>
>> = Eric MacAdie
>>
>>
>

Mime
View raw message