• Post Reply Bookmark Topic Watch Topic
  • New Topic

Networkiing Chat : Sending blank messages issue!  RSS feed

 
stelios papamichael
Ranch Hand
Posts: 93
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there,i am building a networking chat application for me and my friend to chat on and i am facing two issues :

First and foremost here is the class that hold the code needed for this to work :



1) Although i did try both message.equals("") {} and message.isEmpty()..{} none of them works and i can still send blank messages.

2)Also, when i type in a message and append it it appears next to the name like it should but after the 2nd message,every message i type has like two extra spaces in front of it : eg. 1st msg) Hello there! 2nd msg+)     Hello there!
I tried messing with \n and \r but that didn't do the trick.

Please help me resolve this issue and thanks in advance! 
 
Fred Kleinschmidt
Bartender
Posts: 572
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

message.equals("") will ALWAYS be false here, since you have set it equal to name + ":" + message. Even if the original message was empty, and name is empty, message will be equal to ":".

You want to create a new string with a different reference:
 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am a bit puzzled on how your "Networking chat" works. Don't see any server part where client could send messages to, nor any network classes (as ServerSocket, Socket) added which seem vital for sending messages through the network.

Could you please explain a bit more?

Some of your comments are misleading, beware of such comments as on line 29 are. These variables aren't global, they are opposite - instance variables. Same as line 117, methods aren't global (static), these belong to instance and moreover, these are private. Not accessible to outside world at all.
 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, sorry, I didn't notice earlier. It seems you're practicing chat application within the one client for now. Sorry for confusion.
 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Wouldn't make sense to move line 3 down below the if statement block?
 
stelios papamichael
Ranch Hand
Posts: 93
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote:Ah, sorry, I didn't notice earlier. It seems you're practicing chat application within the one client for now. Sorry for confusion.


No problem m8, i am following a tutorial which explains all this and my comments follow what the fellow guy says :P . Please help me correct my comments if you will !
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you own the webapp.com ste? The convention is, only use that format of package name if you own the website name.
Another thing: your code is illegible because of those long comments, which make the lines too long to read.
 
Fred Kleinschmidt
Bartender
Posts: 572
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or even
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would also add, between lines 1 and 2
 
Fred Kleinschmidt
Bartender
Posts: 572
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding trim() is probably correct, unless there is a reason to distinguish between an empty message and a message containing only whitespace characters.
 
stelios papamichael
Ranch Hand
Posts: 93
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Do you own the webapp.com ste? The convention is, only use that format of package name if you own the website name.
Another thing: your code is illegible because of those long comments, which make the lines too long to read.


i do not own any websites,i thought that i could name my package with anything ;p
 
stelios papamichael
Ranch Hand
Posts: 93
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote:

Wouldn't make sense to move line 3 down below the if statement block?


I tried this solution as i thought it really did make sense,but turns out this does not work either
 
stelios papamichael
Ranch Hand
Posts: 93
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred Kleinschmidt wrote:
message.equals("") will ALWAYS be false here, since you have set it equal to name + ":" + message. Even if the original message was empty, and name is empty, message will be equal to ":".

You want to create a new string with a different reference:


I did change my code and used this as a guide but it didn't fix the issue either.I am really puzzled because i don't see anything wrong with the actual piece of code handling this part ;(!
 
stelios papamichael
Ranch Hand
Posts: 93
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I managed to fix the empty message sending issue but i still can't figure out the 2nd problem. :P Any ideas?
 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
stelios papamichael wrote:I managed to fix the empty message sending issue but i still can't figure out the 2nd problem. :P Any ideas?
Maybe because on the line 126 you set not an empty string, but rather white space character?
 
stelios papamichael
Ranch Hand
Posts: 93
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote:
stelios papamichael wrote:I managed to fix the empty message sending issue but i still can't figure out the 2nd problem. :P Any ideas?
Maybe because on the line 126 you set not an empty string, but rather white space character?


Thanks a lot m8,that was it.I was a bit confused with "" and " ".Now it works fine(except from when i press space then an empty msg is sent but that might be fixed on a later tutorial video otherwise if you have any ideas i would be glad to hear it).

 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mind to show us which tutorial is that? You need to try to think yoursel how to prevent from sending such message as space character, in fact, you have been given such hint already.

Show us your recent send method code.
 
stelios papamichael
Ranch Hand
Posts: 93
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote:Do you mind to show us which tutorial is that? You need to try to think yoursel how to prevent from sending such message as space character, in fact, you have been given such hint already.

Show us your recent send method code.


it's called Network Chat Programming by The Cherno Project on youtube.

Send method :


+I tried solving it on my own,i wouldn't have asked otherwise,right now i am also looking on google !
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!