Win a copy of Programmers Guide to Apache Thrift this week in the Open Source forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Using JMS message service point-to-point in a Java program  RSS feed

 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I explained the 'static' error above

Then Paul referred me to a FAQ page which I read and tried to implement
But came stuck on the second next instruction (as I explained above)

Bob M
 
Saloon Keeper
Posts: 5475
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't get too hung up on that tutorial to make progress on the main issue. You can learn about static fields on https://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html

Bottom line: instance fields can't be used from static methods (which is what main is). An easy solution for this pair of classes would be to make the fields static. While that would be OK to make this example work, it would be the wrong solution once you integrate the code into the overall codebase. But the problem wouldn't manifest there, because you wouldn't have static methods.
 
Bob Matthews
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim

I must point out that I have a very narrow and limited knowledge of the java language

I only understand a very small portion of its workings

I understand that I need to make some changes to the code which you posted and which works as a stand-alone example, before I can incorporate it into my java program

I think that I need to remove the word 'static' and the word 'main' but that's it

So am floundering due to lack of knowledge

Bob M
 
Bob Matthews
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some progress to date..................................

Added the word 'static to both classes (Socket Server and Socket Client) code

Clean compile on Socket Server code but

1 compile error on the Socket Client code

reference to Trading_Decision_2 (original line 68)

error] cannot make a static reference to the non-static field Trading_Decision_2

which is a variable calculated earlier on in the large java program

what changes do I need to make to the variable Trading_Decision_2 ?

Bob M
New Zealand
 
Tim Moores
Saloon Keeper
Posts: 5475
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seeing as you have put a lot of effort into this, I'll make an exception to our rule and post the full code of client and server that use no static fields. There's a static main method, but that's just for testing.

In the server code, the important lines are 9 and 10, which you need to incorporate into your larger code. On the client side, it's lines 16 and 17.

The code completely punts on error handling, which obviously your code can't do once you put it into use.

The other issue is that the server waits until "exit" is sent before returning. So you can't call it from the main thread of your larger app, as it would block it. It needs to be called from a background thread.




 
Bob Matthews
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On Client side is it lines 14 & 15 ?

Bob M
 
Tim Moores
Saloon Keeper
Posts: 5475
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh right, I had edited the post.
 
Bob Matthews
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim

I have removed lines 9-16 of the Socket Client code above

In my larger program I have the following.............



but I feel there is no message being sent ?

Bob M
 
Tim Moores
Saloon Keeper
Posts: 5475
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean, "you feel"? Is anything output on the client or the server side? Any exceptions?
 
Bob Matthews
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No

Server side: background thread starts and server listens

Client side: I don't see "we get to here - zz"

Bob M
 
Why is the word "abbreviation" so long? And this ad is so short?
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!