• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Java server-client problem while using Scanner

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone, this is my first time uploading here, so please be gentle :P I am writing the code for a server-client program that exchanges messages and the server asks the client for some information. Although the code works, when I run the program and it asks from the client to enter an Integer, it requires for the integer to be entered twice before it is accepted and I can see no obvious reason why this is happening. Could someone enlighten me?




The console output for the client is this:

The client is connected to: IliasGk-PC/192.168.1.5 on port: 13000
Please enter your name here:
Ilias
Server says: Selling IliasGk-PC/192.168.1.5
Server says: Type 'Catalogue' to see the available products or 'Bid' to make an offer.
Server says: If you want to terminate the connection at any time, please type 'EXIT'
Bid
Server says: Which item are you interested in buying?
Server says: Please select by an integer ID
1
1
Server says: You have selected: LG G2
Server says: Please enter your bid:
300
300
Server says: Your bid is accepted. Enjoy your new phone.
Server says: Your connection will now be terminated. Thank you for buying our product.

 
Marshal
Posts: 76447
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Don't know. I can see nothing in that method which requires double input; maybe the error is somewhere else.
 
Ilias Kanellos
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for the welcome and for the reply The "interesting" thing is that there is no Exception thrown on the Server's side or anything and I just figured out that the first time the input is given, it is passed on to the server as a simple message and not as an int i variable... Server's output for the mentioned "conversation" is:

The server is up.
Connection established. Client number: 1
Buying Ilias
Client '1' says: 1
Client '1' says: 300
Socket closed

I've been trying to troubleshoot this for a few days and it's driving me insane :P
 
Campbell Ritchie
Marshal
Posts: 76447
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You wouldn't expect there to be any Exceptions. Sorry, still can't see what is going wrong.
 
Ilias Kanellos
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyway, thank you for your time and trouble. I guess I will figure out something when I'm in "deadline inspiration" mode
 
Ilias Kanellos
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I marked this as resolved because I found out what was causing the problem. You were right Mr. Campbell the problem was in another part of the code. Thank you again
 
Campbell Ritchie
Marshal
Posts: 76447
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done Please show us what the problem really was.
 
expectation is the root of all heartache - shakespeare. tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic