Win a copy of Event Streams in Action this week in the Java in General 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

problem launching a socket client

 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Client code



and I am trying to launch a client by the following line of code

Client client = new Client();

Is this correct ?
 
Saloon Keeper
Posts: 5707
144
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If afterwards the "run" method is called, it looks OK. Otherwise, no, as the constructor by itself does nothing.
 
Bob Matthews
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I call the 'run' method ?

I have tried

run.client(args);

but I get an error

args cannot be resolved to a variable
 
Ranch Hand
Posts: 92
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you wanted something like:

client.run()

You just need to replace String[] with String... on line six if you want to use this method without providing any parameters
 
Bob Matthews
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tried that............

but...........error

The method run(String) is not applicable for the arguments()
 
Tim Moores
Saloon Keeper
Posts: 5707
144
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try "client.run(args)", provided args is a string array.
 
Bob Matthews
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
launcher is now


and in line 6 above of the client code have replaced String[] with String

No sign of any client action ???
 
Tim Moores
Saloon Keeper
Posts: 5707
144
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the server up and running? If not, the code will eventually time out in line 14 (and throw an exception to that effect). I just tested it, and it timed out after more than a minute.
 
Adrian Grabowski
Ranch Hand
Posts: 92
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bob Matthews wrote:

and in line 6 above of the client code have replaced String[] with String

No sign of any client action ???



String... (with three dots)

This will allow you to call the method with or without parameters.
 
Bob Matthews
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adrian - sorry misunderstood - now String...

Tim - I believe so

will see what happens on the next hour
 
Bob Matthews
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Server code


and very early on in the large java program running on the server computer, I launch the above with

Thread thread = new Thread();
thread.start();

I don't think neither the server code nor the client code is being actioned ???
 
Tim Moores
Saloon Keeper
Posts: 5707
144
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Thread thread = new Thread();


Should this read "new NewThread()", or is that a typo?
 
Bob Matthews
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim - typo - yes

NewThread is running (on server)

but in printing out Trading decisions - it is evident that no message came from client

At this point, I am struggling with debugging tools
 
Marshal
Posts: 65038
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:Also posted here . . .

Please always tell people on each website if you post on multiple sites.
 
Bob Matthews
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm - please disregard that conversation as I have updated my code

My problem (server code) lies between starting a new thread and "a new client is connected" message not appearing
 
Norm Radder
Rancher
Posts: 3409
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

please disregard that conversation as I have updated my code


Please update the status on the other site.
 
Bob Matthews
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have put some debugging lines of code in both client and server

On client side:

it prints out a debug message BEFORE and AFTER the line


On server side:

it prints out a debug message BEFORE but not AFTER the line


I feel I need some suggestions on the server side code
 
Bob Matthews
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when the server runs for a second time I get the following errors (to be read upwards)

Time               Messages                                                                                
2019-07-18 23:00:00 at my_strategies.us_copiosus_EURCAD_1010$NewThread.run(us_copiosus_EURCAD_1010.java:1695)
2019-07-18 23:00:00 at my_strategies.us_copiosus_EURCAD_1010$Server.run(us_copiosus_EURCAD_1010.java:1712)  
2019-07-18 23:00:00 at java.net.ServerSocket.<init>(Unknown Source)                                          
2019-07-18 23:00:00 at java.net.ServerSocket.<init>(Unknown Source)                                          
2019-07-18 23:00:00 at java.net.ServerSocket.bind(Unknown Source)                                            
2019-07-18 23:00:00 at java.net.PlainSocketImpl.bind(Unknown Source)                                        
2019-07-18 23:00:00 at java.net.AbstractPlainSocketImpl.bind(Unknown Source)                                
2019-07-18 23:00:00 at java.net.DualStackPlainSocketImpl.socketBind(Unknown Source)                          
2019-07-18 23:00:00 at java.net.DualStackPlainSocketImpl.bind0(Native Method)                                
2019-07-18 23:00:00 java.net.BindException: Address already in use: JVM_Bind                                
2019-07-18 23:00:00 Server exception occurred: java.net.BindException: Address already in use: JVM_Bind

which suggests that a socket address was setup the first time the program ran (i.e. an hour ago)

Is this a correct interpretation of the above ?
     
 
Bob Matthews
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
something else which is puzzling me...................

I have debugging lines such as


when I try to place a line like this inside Server class or Client class it won't compile and shows that line in error

I have never seen this before
 
Bob Matthews
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Update:

Messages:- (on server)

A new client is connected:Socket[addr=/10.1.1.10, port=59529, localport=9873]
Assigning new thread for this client

but still no transfer of message
I am wondering whether my problem is around the DataInputStream & DataOutputStream

I am attempting to print them out but not seeing anything
 
Not so fast naughty spawn! I want you to know about
Java Code Review and Psychology
https://coderanch.com/t/714798/java/Java-Code-Review-Psychology
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!