You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Peter Dawn <pe...@gmail.com> on 2006/05/30 00:30:14 UTC

TCP-IP Communication help

hi all,

i am working on implementing TCP/IP socket communication within my web
app. I have been able to send messages from a set port to an external
application (a dummy server program) and that application is able to
receive my send messages.

however I am unable to receive messages back from the external
application. actually when the application does send something back I
am able to read something, but its all gibberish.

this is my code for receiving data from the application,

int avInt = in.available();

String avStr = "";
Debug.println("Number of bytes sent: " + avStr.valueOf(avInt));

int x = 0;
StringBuffer y = new StringBuffer();
while (x < avInt) {
   char b = in.readChar();
   String a = "";
   y.setLength(1);
   y.setCharAt(0,(char)b);
   Debug.println("+++++" + y.toString());
   x++;
}

now when i send asdfas from the server, i receive
+++++?
+++++?
+++++?
+++++?
+++++?
+++++?

obviously i am expecing to read asdfas.

any help guys. thanks in advance.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: TCP-IP Communication help

Posted by Peter Dawn <pe...@gmail.com>.
finally got it to work. the trick was to create another thread for it.
so now i have a new listener class which is running in the background
in sep threads for sending and receiving data. thanks to all for their
help.

the only other thing I can see is that my web.xml is flagging an error
on the last line of the file at </web-app> for some reason. it seems
to have compiled and its running properly, but somehow eclipse is not
happy with the file.

dont know whats wrong though. there is no syntax error in my listener
statements. can you guys think of anything.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: TCP-IP Communication help

Posted by Peter Dawn <pe...@gmail.com>.
right so thats the problem, my socket call is a blocking call and i
should start it in a new thread. thanks jesse, will give that a shot
and see how i go. i will keep the current implementation and will only
add a sep thread for it. let me know if you think of something else.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: TCP-IP Communication help

Posted by Jesse Kuhnert <jk...@gmail.com>.
Do you mean you are doing a ServerSocket.bind() call? You need to do that in
a new thread, it's a blocking call.

On 5/30/06, Peter Dawn <pe...@gmail.com> wrote:
>
> i have implemented a separate listener-class which includes the
> context-initiliazed and contextdestroyed methods. i have put my socket
> connection stuff in the initialized method.
>
> it seems to load up with tomcat and with the webapp and is working
> fine. the problem is that once its started the socket is waiting for
> any messages to be recieved and in the meantime the web app does not
> load up any further, once i send  a message to it, it works fine
> again.
>
> so i am back to my original problem, i want it to open up a socket in
> the background and wait for communication but the web app should work
> fine in the meantime, the process shouldnt stop anything.
>
> any help guys.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Jesse Kuhnert
Tacos/Tapestry, team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind.

Re: TCP-IP Communication help

Posted by Peter Dawn <pe...@gmail.com>.
i have implemented a separate listener-class which includes the
context-initiliazed and contextdestroyed methods. i have put my socket
connection stuff in the initialized method.

it seems to load up with tomcat and with the webapp and is working
fine. the problem is that once its started the socket is waiting for
any messages to be recieved and in the meantime the web app does not
load up any further, once i send  a message to it, it works fine
again.

so i am back to my original problem, i want it to open up a socket in
the background and wait for communication but the web app should work
fine in the meantime, the process shouldnt stop anything.

any help guys.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: TCP-IP Communication help

Posted by Mark Stang <ms...@pingidentity.com>.
Peter,
Are you thinking of using iframes?  We tried using those and it worked quite well, until someone turned on IE security.  At the higher levels of IE Security things stopped working.  However, ours was with an automated download, your experience may vary.  You can also just insert a component in the page and have it start up the process.

regards,

Mark


-----Original Message-----
From: Peter Dawn [mailto:petedawn@gmail.com]
Sent: Tue 5/30/2006 5:07 PM
To: Tapestry users
Subject: Re: TCP-IP Communication help
 
both hivemind and "ServletContextListener" look good. need to do a bit
of reading on both i guess.

what do you guys think of just putting that code into a separate class
and into a hidden frame and let it start in the background.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org




Re: TCP-IP Communication help

Posted by Peter Dawn <pe...@gmail.com>.
both hivemind and "ServletContextListener" look good. need to do a bit
of reading on both i guess.

what do you guys think of just putting that code into a separate class
and into a hidden frame and let it start in the background.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: TCP-IP Communication help

Posted by Paul Cantrell <ca...@pobox.com>.
I like to use a ServletContextListener to do this: start your  
service's thread in contextInitialized(), and end it in  
contextDestroyed(). Google "ServletContextListener" for more info.

On May 30, 2006, at 3:44 AM, Peter Dawn wrote:

> i will try and have a look at it.
>
> another way of looking at my question is, whats the best way of
> running a program in the background as a service within the web app
> without halting any other processes or programs.
>
> any thought.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

_________________________________________________________________
Piano music podcast: http://inthehands.com
Other interesting stuff: http://innig.net



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: TCP-IP Communication help

Posted by Jesse Kuhnert <jk...@gmail.com>.
http://jakarta.apache.org/hivemind/

On 5/30/06, Peter Dawn <pe...@gmail.com> wrote:
>
> i will try and have a look at it.
>
> another way of looking at my question is, whats the best way of
> running a program in the background as a service within the web app
> without halting any other processes or programs.
>
> any thought.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Jesse Kuhnert
Tacos/Tapestry, team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind.

Re: TCP-IP Communication help

Posted by Peter Dawn <pe...@gmail.com>.
i will try and have a look at it.

another way of looking at my question is, whats the best way of
running a program in the background as a service within the web app
without halting any other processes or programs.

any thought.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: TCP-IP Communication help

Posted by Stephane Decleire <sd...@cariboo-networks.com>.
Have you tried to use the asynchronous functions of the socket API 
instead of the synchronous ones ?

Peter Dawn wrote:

> jesse,
>
> thanks for your feedback.
>
> though, i have managed to get TCP/IP communication happening within
> the web application. by that i mean that my web app can send and
> receive messages to another app on a set port.
>
> but i am not sure how should i run this process. i mean i would like
> to run this process as soon as my web app starts-up. i tried putting
> it in the PSEngine class where it also connects to the db and it looks
> to work fine with just one problem, after the socket is opened up, its
> waiting for some response from the server and in the meantime the
> application is not loading up. even if the external application sends
> a message, my web app is able to receive it but its not going ahead
> any further. i mean the pages are not rendering and it seems to be not
> going past it.
>
> i am thinking of perhaps putting this functionalty into a hidden frame
> where it doesnt block anything. can somebody think of a better way of
> doing this.
>
> thanks for all the help.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

-- 
Stéphane Decleire

05 56 57 99 20
06 63 78 69 06


Re: TCP-IP Communication help

Posted by Peter Dawn <pe...@gmail.com>.
jesse,

thanks for your feedback.

though, i have managed to get TCP/IP communication happening within
the web application. by that i mean that my web app can send and
receive messages to another app on a set port.

but i am not sure how should i run this process. i mean i would like
to run this process as soon as my web app starts-up. i tried putting
it in the PSEngine class where it also connects to the db and it looks
to work fine with just one problem, after the socket is opened up, its
waiting for some response from the server and in the meantime the
application is not loading up. even if the external application sends
a message, my web app is able to receive it but its not going ahead
any further. i mean the pages are not rendering and it seems to be not
going past it.

i am thinking of perhaps putting this functionalty into a hidden frame
where it doesnt block anything. can somebody think of a better way of
doing this.

thanks for all the help.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: TCP-IP Communication help

Posted by Jesse Kuhnert <jk...@gmail.com>.
Using socket IO communications has little to do with tapestry development,
unless you are talking about IO from browser to server. Maybe your case is
different?

I would go look at the tutorials on the java.sun.com website about socket IO
and create very tiny test classes that don't run in any other container to
confirm my functionality first before complicating it with web app stuff.

On 5/29/06, Peter Dawn <pe...@gmail.com> wrote:
>
> hi all,
>
> i am working on implementing TCP/IP socket communication within my web
> app. I have been able to send messages from a set port to an external
> application (a dummy server program) and that application is able to
> receive my send messages.
>
> however I am unable to receive messages back from the external
> application. actually when the application does send something back I
> am able to read something, but its all gibberish.
>
> this is my code for receiving data from the application,
>
> int avInt = in.available();
>
> String avStr = "";
> Debug.println("Number of bytes sent: " + avStr.valueOf(avInt));
>
> int x = 0;
> StringBuffer y = new StringBuffer();
> while (x < avInt) {
>    char b = in.readChar();
>    String a = "";
>    y.setLength(1);
>    y.setCharAt(0,(char)b);
>    Debug.println("+++++" + y.toString());
>    x++;
> }
>
> now when i send asdfas from the server, i receive
> +++++?
> +++++?
> +++++?
> +++++?
> +++++?
> +++++?
>
> obviously i am expecing to read asdfas.
>
> any help guys. thanks in advance.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Jesse Kuhnert
Tacos/Tapestry, team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind.