Chat application in Grails [closed] - grails

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am trying to create a chat application in grails. I have no idea on doing this, so can you please point me in the correct direction. The application need not to be fancy, I just want a simple application.
Thanks

There is a blog that outlines the basic principles of this:
http://programmingitch.blogspot.co.uk/2010/04/groovy-sockets-example.html
import java.net.ServerSocket
def server = new ServerSocket(4444)
while(true) {
server.accept { socket ->
println "processing new connection..."
socket.withStreams { input, output ->
def reader = input.newReader()
def buffer = reader.readLine()
println "server received: $buffer"
now = new Date()
output << "echo-response($now): " + buffer + "\n"
}
println "processing/thread complete."
}
}
This gives you the basic socket connections and input/output streams for a connected client. You would have to adjust this to keep track of multiple clients and broadcast (send to all connected users) any messages from the server.

Related

Groovy AntBuilder file sorting [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
groovy AntBuilder style select sorted files:
def ant = new AntBuilder();
def files = ant.first(count:1){
sort(){
fileset(dir:/R:\goagent2/){
depth max:0
}
// reverse(){ date(); }
date()
}
}*.file;
Why not just do it with plain Groovy?
def oldestFile = new File( /R:\goagent2/ ).listFiles()
.sort { it.lastModified() }
.head()

Get Key value of a hash in sort order [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
Here is my code
{"wow"=>["wow"], "you"=>["you", "you"], "are"=>["are"], "a"=>["a"], "good"=>["good"], "guy"=>["guy"], "but"=>["but"], "sometime"=>["sometime"], "take"=>["take"], "very"=>["very"], "wrong"=>["wrong"], "decision"=>["decision"]}
i want to get result
{"you"=>2, "are"=>1, "a"=>1, "good"=>1, "guy"=>1, "but"=>1, "sometime"=>1, "take"=>1, "very"=>1, "wrong"=>1, "decision"=>1,"wow" =>1}
how can i do this please help me
Try
old_hash = {"wow"=>["wow"], "you"=>["you", "you"], "are"=>["are"], "a"=>["a"], "good"=>["good"], "guy"=>["guy"], "but"=>["but"], "sometime"=>["sometime"], "take"=>["take"], "very"=>["very"], "wrong"=>["wrong"], "decision"=>["decision"]}
new_hash = Hash.new
old_hash.each {|k,v| new_hash.merge!(k=>v.size) }

populating Grails domain classes [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I wrote a simple code to populate the Grail domain classes and a code for showing db contents, but it doesn't work. Attached is my code! I appreciate any help.
def populateDB(int nofelements)
{
def instance
for (int i=1;i<=nofelements;i++){
instance=new Avendpoint()
instance.avName=org.apache.commons.lang.RandomStringUtils.random(9, true, true)
instance.bridge=org.apache.commons.lang.RandomStringUtils.random(9, true, true)
instance.callerID=org.apache.commons.lang.RandomStringUtils.random(9, true, true)
instance.con=false
instance.state=AvendpointState.ONE_WAY
instance.uid=org.apache.commons.lang.RandomStringUtils.random(5, true, true)
instance.save(flush: true)
}
render "The database has been populated successfully!"
}
def showDB(){
def instance
String res
res+=Integer.toString(Avendpoint.count())
for(int i=1; i<Avendpoint.count(); i++){
instance=Avendpoint.get(i)
res+=instance.avName+"<br>"+instance.bridge+"<br>"+instance.callerID+"<br>"+
instance.con+"<br>"+instance.state+"<br>"+instance.uid+"<br>"
}
render res
}
The first thing is try to use: instance.save(flush: true,failOnError:true). By default Grails doesn't throw an exception when domain doesn't it's fields constraints. Maybe instances are rejected while validation and will not be saved.

remove html characters in blackberry java [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
how to remove html characters in a webservice in blackberry java ?
(ie remove "$" withString "%24" and "&" withString "%26" and so on..)
You would use one of the many freely-available URL encoders. Search for "blackberry url encoder" or "java me url encoder" or something similar. For example, here's one and here's another.
It's always been a mystery to me why URL encoding and decoding was not included in either MIDP or the BlackBerry API given that it's so useful.
String s="http://199.199.199.199/webservices/login.php";
int b = (int)s.charAt(i++);
if ((b>=0x30 && b<=0x39) || (b>=0x41 && b<=0x5A) || (b>=0x61 && b<=0x7A)) {
tmp.append((char)b);
}
else {
tmp.append("%");
if (b <= 0xf) tmp.append("0");
tmp.append(Integer.toHexString(b));
}
Dialog.alert(tmp.toString());
}

search aspx page data to find out [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
how to search the file and folder seach page
To list Files and Folders you can use something called DirectoryInfo
EXample
void Page_Load(object s, EventArgs e)
{
DirectoryInfo di = new DirectoryInfo("c:/inetpub/wwwroot/demos");
FileInfo[] rgFiles = di.GetFiles("*.aspx");
foreach(FileInfo fi in rgFiles)
{
Response.Write("<br>" + fi.Name + "");
}
}
example taken from here

Resources