Author Topic: An Advanced Chat  (Read 3828 times)

0 Members and 1 Guest are viewing this topic.

Offline Dale

  • Hero Member
  • *****
  • Posts: 660
  • LOL IM COOL
    • View Profile
An Advanced Chat
« on: April 12, 2007, 05:22:11 pm »
I just got to thinking, What way should I create my Advanced Chat Client/Server?

I've always have used text/based commands through winsock, But this is quite secure, so how would I go about doing it? Any suggestions?

Quote
[1:53:54 PM] Ersan: i could've written iago's code in 20 minutes
Quote
Joetheodd: I just gave myself the right arm workout of the century.
DMSyph: Uh ew?
Joetheodd: Oh my God.. I just realized what that probably could mean..
Quote
Kitty: Well honey, Canadians don't matter.
Dude, peanutbutter and jelly is like...1000000x more intense than a Volvo.

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10330
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: An Advanced Chat
« Reply #1 on: April 12, 2007, 05:29:45 pm »
Take a look at JoeChat. I wrote it probably almost a year ago now, so that was back when I had less skill, etc, whatever, but I was pretty proud of it at the time.

The only thing is that it's P2P instead of Server-Client.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Ender

  • x86
  • Hero Member
  • *****
  • Posts: 2398
    • View Profile
Re: An Advanced Chat
« Reply #2 on: April 12, 2007, 05:38:38 pm »
I just got to thinking, What way should I create my Advanced Chat Client/Server?

I've always have used text/based commands through winsock, But this is quite secure, so how would I go about doing it? Any suggestions?

What language? C#? C++? VB?

Offline Ender

  • x86
  • Hero Member
  • *****
  • Posts: 2398
    • View Profile
Re: An Advanced Chat
« Reply #3 on: April 12, 2007, 05:50:02 pm »
I just got to thinking, What way should I create my Advanced Chat Client/Server?

I've always have used text/based commands through winsock, But this is quite secure, so how would I go about doing it? Any suggestions?

In mine I just translated text commands to byte ids, like /join->5 or something, instead of sending the text as-is to the server. Is that what you meant? And why do you say "secure"? If you don't want your client to be emulated, then make a login that's hard to emulate.

Offline Dale

  • Hero Member
  • *****
  • Posts: 660
  • LOL IM COOL
    • View Profile
Re: An Advanced Chat
« Reply #4 on: April 12, 2007, 06:04:11 pm »
I just got to thinking, What way should I create my Advanced Chat Client/Server?

I've always have used text/based commands through winsock, But this is quite secure, so how would I go about doing it? Any suggestions?

In mine I just translated text commands to byte ids, like /join->5 or something, instead of sending the text as-is to the server. Is that what you meant? And why do you say "secure"? If you don't want your client to be emulated, then make a login that's hard to emulate.

Yeah, I actually thought of using that idea

Take a look at JoeChat. I wrote it probably almost a year ago now, so that was back when I had less skill, etc, whatever, but I was pretty proud of it at the time.

The only thing is that it's P2P instead of Server-Client.

Thanks, I'll take a look.

I just got to thinking, What way should I create my Advanced Chat Client/Server?

I've always have used text/based commands through winsock, But this is quite secure, so how would I go about doing it? Any suggestions?

What language? C#? C++? VB?

Probably VB, I haven't had time to learn sockets in any other language besides Python. Haha.
Quote
[1:53:54 PM] Ersan: i could've written iago's code in 20 minutes
Quote
Joetheodd: I just gave myself the right arm workout of the century.
DMSyph: Uh ew?
Joetheodd: Oh my God.. I just realized what that probably could mean..
Quote
Kitty: Well honey, Canadians don't matter.
Dude, peanutbutter and jelly is like...1000000x more intense than a Volvo.

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17931
  • Fnord.
    • View Profile
    • SkullSecurity
Re: An Advanced Chat
« Reply #5 on: April 13, 2007, 04:47:14 pm »
I recommend basing it on HTTP. If you don't know the specs for HTTP, all the better to learn!

HTTP is very extensible, has a ton of room for meta-data, and is already used for a lot of different things (besides web traffic).

Offline Dale

  • Hero Member
  • *****
  • Posts: 660
  • LOL IM COOL
    • View Profile
Re: An Advanced Chat
« Reply #6 on: April 13, 2007, 07:19:37 pm »
what do you mean? give an example?
Quote
[1:53:54 PM] Ersan: i could've written iago's code in 20 minutes
Quote
Joetheodd: I just gave myself the right arm workout of the century.
DMSyph: Uh ew?
Joetheodd: Oh my God.. I just realized what that probably could mean..
Quote
Kitty: Well honey, Canadians don't matter.
Dude, peanutbutter and jelly is like...1000000x more intense than a Volvo.

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17931
  • Fnord.
    • View Profile
    • SkullSecurity
Re: An Advanced Chat
« Reply #7 on: April 13, 2007, 08:05:33 pm »
HTTP works as a request/response system. Generally, a request will be like this:

Code: [Select]
[action] [path or object] [version]
[param1]: [value1]
[param2]: [value2]
[paramn]: [valuen]

[data, if a length is specified in content-length parameter; otherwise, nothing]


The parameter list always ends with two newlines, followed by data, if applicable.

The responses are:
Code: [Select]
[protocol] [response code] [response text]
[param1]: [value1]
[param2]: [value2]
[paramn]: [valuen]

[data, if a length is specified in content-length parameter; otherwise, nothing]

Here is an example from my browser, which shows a post thread and a redirection:

SENT:
Code: [Select]
POST /forum/index.php?action=post2;start=0;board=24 HTTP/1.1
Host: www.x86labs.org:81
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.x86labs.org:81/forum/index.php?action=post;board=24.0
Cookie: --- snip ---
Content-Type: multipart/form-data; boundary=---------------------------1164562419858532411229733600
Content-Length: 1610

-----------------------------1164562419858532411229733600
Content-Disposition: form-data; name="subject"

Test
-----------------------------1164562419858532411229733600
Content-Disposition: form-data; name="icon"

xx
-----------------------------1164562419858532411229733600
Content-Disposition: form-data; name="message"


test
--- snip ---


RECEIVED:
Code: [Select]
HTTP/1.1 302 Found
Date: Fri, 13 Apr 2007 23:59:29 GMT
Server: Apache/2.2.2 (Unix)
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: private
Pragma: no-cache
Location: http://www.x86labs.org:81/forum/index.php/topic,9077.new.html#new
Content-Encoding: gzip
Vary: Accept-Encoding
Content-Length: 26
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html

SENT:
Code: [Select]
GET /forum/index.php/topic,9077.new.html HTTP/1.1
Host: www.x86labs.org:81
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.x86labs.org:81/forum/index.php?action=post;board=24.0
Cookie: --- snip ---


RECEIVED:
Code: [Select]
HTTP/1.1 200 OK
Date: Fri, 13 Apr 2007 23:59:29 GMT
Server: Apache/2.2.2 (Unix)
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Cache-Control: private
Pragma: no-cache
Last-Modified: Fri, 13 Apr 2007 23:59:29 GMT
Content-Encoding: gzip
Vary: Accept-Encoding
Content-Length: 7269
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: text/html; charset=ISO-8859-1

--- snip ---


I wrote a really nice Java library that could handle sending and receiving commands, and all commands had a response (even if it was an error). It worked really nicely. It's so flexible that you can do a lot, and it compresses extremely well if bandwidth is a concern. It's also extremely easy to troubleshoot. I had a flag I could set to turn compression off for troubleshooting.

Offline Skywing

  • Full Member
  • ***
  • Posts: 146
    • View Profile
    • Nynaeve
Re: An Advanced Chat
« Reply #8 on: April 14, 2007, 08:44:31 pm »
HTTP is not very ideal for a chat system, or anything else that utilizes some sort of real-time, bidirectional communication.  You'll generally need to have parties who wish to receive data pend multiple requests to the server, which completes them when new data is available.  Polling in this fashion is undesirable as far as latency, overhead, and transfer speed are concerned (not to mention that you are using up multiple TCP connections per client if you attempt to make the latency less painful by pending multiple HTTP requests instead of a single request).
« Last Edit: April 14, 2007, 08:46:32 pm by Skywing »

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17931
  • Fnord.
    • View Profile
    • SkullSecurity
Re: An Advanced Chat
« Reply #9 on: April 14, 2007, 09:25:15 pm »
I didn't actually mean using exact HTTP request syntax, but rather to use similar packet structure. I wrote a module that implemented a HTTP-style syntax, but allowed for bi-directional requests on the same socket, and I found it worked quite well.

Offline Skywing

  • Full Member
  • ***
  • Posts: 146
    • View Profile
    • Nynaeve
Re: An Advanced Chat
« Reply #10 on: April 14, 2007, 09:42:53 pm »
Regardless, though, HTTP involves a great deal of unwieldy and potentially error-prone string parsing all over the place as well.  If I were designing a protocol from scratch, I would rather go for something that utilizes TLVs (like RADIUS) for generic and easy parsing.

TLVs get you the generic parsing of a simple list of standard character delimited strings with the convenience and ease of use of most binary protocols from an implementation / parsing standpoint.

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17931
  • Fnord.
    • View Profile
    • SkullSecurity
Re: An Advanced Chat
« Reply #11 on: April 14, 2007, 10:35:44 pm »
Well, when I implemented HTTP, I was also trying to teach myself about finite state machines and string parsing, so that encouraged me.

You're right about it being unwieldy, but it could also serve good from an academic standpoint, if he's into that.

I don't know anything about TLVs, so I'll skip commenting on that.