Valhalla Legends Forums Archive | Java Programming | Simple Chat Program

AuthorMessageTime
Ender
I'm making a "simple chat program." This is not a bot; I wrote my own server and client. My goals are 1) room messaging and 2) private messaging. For goal #1, I just echo messages (parsed from packets) back to everyone but the sender. I have not yet implemented goal #2, I am still trying to make goal #1 work! I wrote separate client and server programs, which compile fine, but don't do what I want. Is anyone up for correcting my code and helping me make this program work. I will share all code! It will be educational (well, for me, maybe not you...)!

If you are up for working on it together, say so here and email me at dijame@gmail.com . Note: I already wrote the code, so the "work" is in debugging and correcting.
January 2, 2006, 1:15 AM
Kp
If you have a general idea about where the problem lies, why not just post the code in a message here?  If it's too long, post it on a webspace somewhere and link to it.  The board already has an e-mail notify feature, so I'm not going to mail you to tell you I've responded.  That's more work for me when you're the one who should be doing more work!
January 2, 2006, 1:37 AM
Ender
Ok. I posted pretty much the same post on Sun's forums, but with all the code attached. I'll link you there. They have pretty colors too! code

In order to read the program more easily, basically the order of events follows the order of classes provided. For the server program, the Main method creates a Server object and passes that Server object to the Parser object to be used for parsing. In the client program, the Main method creates a Parser object, and passes it the hostname and port to connect to. The parser object talks to the server and does the parsing. It's a really simple program, but my first attempt at making a chat program with a protocol. I've made simpler client-server programs that echo back messages, but these programs don't have a protocol and thus don't need to be parsed.

Now, as to where the problem lies... somewhere in one of the Parser classes and maybe the Server class in the server program :) Sorry I can't be more specific! I'm going to look over it myself, and I hope that some of you guys do too =-p. By the way, I "unsign" all the data by storing the bytes I receive as shorts instead, since the shorts clear the carry bit. This unsigned data will be used for parsing (switching the message ID and all). The client does the same. (Java interprets all data (except chars) as signed.)

On the Sun forums I never posted my simple chat protocol. It's just for testing purposes. I haven't even implemented logon packets in the program, nor the 0x0E packet which requests private messaging. Anyways, here it is:
[code]
@author Andy
Created on 1/1/06
--------------------
SIMPLE CHAT PROTOCOL
--------------------
Notes:
- WORD length corresponds to the 80x86 platform, 32-bit architecture
      > DWORD = 32 bit integer
      > WORD  = 16 bit integer
      > BYTE  = 8 bit  integer
- All data is unsigned

1) Header

(BYTE) Always 0x0F
(BYTE) Message ID
(BYTE) Message Length
(VOID) Message Data

2) Messages
--------------------------
a) 0x0A: (Login Message)

(STRING) Username
(STRING) Password
--------------------------
b) 0x0E: (Room Message)

(STRING) Text Message
--------------------------
c) 0x0D: (Private Message)

(STRING) Recipient
(STRING) Text Message
--------------------------
[/code]

EDIT:

One edit I made to my code (posted one Sun's forums, linked above) was the client sent the wrong message length. The edit is:
[code]
      // message length is the three header bytes + the length of the message data (text message "hello world")
      out.write((byte) (msg.length + 3)) // for message length
[/code]
January 2, 2006, 1:46 AM
Ender
Yay! It's semi-working! Lots of edits made, all of which aren't reflected on Sun forums. Why? Because Sun's forums SUCK, they don't let you edit posts! (Grr....)

Anyways, yay, it's semi-working! And right now I'm typing and my letters are appearing on the screen really slowly because 2 client progs + 1 server prog + eclipse > my computer.

EDIT:

Oh yeah, it's "semi-working" because it's printing out weird stuff instead of "hello world."

EDIT2:

I know specifically where the problem lies now. Can anyone see anything wrong in my server program's parsing, specifically in how it translates bytes -> shorts -> bytes. Because "hello world" is coming in, and weird stuff is coming back. Example:

Input from client1: "hello world"
Echo output from client2:
[B@c9ba38
[B@1e0be38
[B@1e859c0
[B@15c7850
January 2, 2006, 2:41 AM

Search