Computer Science Canada

[tutorial]Chat Program

Author:  Delta [ Fri Mar 21, 2003 6:55 pm ]
Post subject:  [tutorial]Chat Program

This is all you need to create the base of any chat program in TURING
code:

var stream : int := 0 % Used for sending data
var msgBack : string % The message that gets sent back and forth
var address : string % IP address for each computer
var message : string  % Message that you send
var status : int % Status host/client

const PORT := 5555 % Port to connect through

put "What would you like to do?"
put "1:Host"
put "2:Join"

get status

if status = 1 then
    stream := Net.WaitForConnection (PORT, address) % Wait for a user to connect
else
    put "What is the IP of the computer you want to connect to?"
    get address
    stream := Net.OpenConnection (address, PORT) % Connect to the IP inputted
end if
cls
put "Connected to ", address

loop
    if hasch then % If key pressed
        get message : *  % store all input in var message when enter is pressed
        put : stream, message  % Send the message over the stream
    end if
    if Net.LineAvailable (stream) then % If a line of text has been sent
        get : stream, msgBack : * % grab the line of text
        put msgBack % print it to the screen
    end if
end loop


MOD Edit: Woot, first user submited tutorial. Thx Delta +10 bits - Tony

Author:  Blade [ Sat Mar 22, 2003 12:16 am ]
Post subject: 

haha yeah! Very Happy *eyeballs it* looks kinda familiar... haha maybe its cuz he wrote it for me to learn off of Very Happy i'm so special! Very Happy

Author:  Delta [ Sat Mar 22, 2003 12:59 am ]
Post subject: 

If anyone has any problems don't be shy ask me them through the forum and I might be able to help you or you can email me. Very Happy

THNX

Author:  leepham [ Mon Mar 24, 2003 3:22 pm ]
Post subject:  ...

Is there any reason why it doesn't work properly? The text is delayed, and it seems like it doesn't register some of the text sometimes.

Lee Pham

Author:  Tony [ Mon Mar 24, 2003 4:36 pm ]
Post subject: 

turing is not the best language to code networked data exchange for a bunch of reasons. Its slow and unreliable. The code here is fine, its the language itself (or perhaps the network Confused)

turing also has a bug where sometimes it cuts off first few characters of the message send... so you might want to add a space or two at the beginning of the line just in case

Author:  Miyoko [ Mon Mar 31, 2003 1:30 pm ]
Post subject: 

I have a problem with it, some computers will wait for a client
Quote:
stream := Net.WaitForConnection (PORT, address)

others will just bypass this line and foget the wait which makes to program crash when you get to
Quote:
put "Connected to ", address

Author:  Delta [ Mon Mar 31, 2003 2:03 pm ]
Post subject: 

Yeah I had the same problem I couldn't find a way to get around it.

Author:  ferrara_999 [ Tue Sep 09, 2003 4:44 pm ]
Post subject:  address

what are the addesses for the various messenger services so it'll connect to em? (like msn messenger and icq)

Author:  Homer_simpson [ Tue Sep 09, 2003 4:55 pm ]
Post subject: 

bwahahahaha!!! i doubt that very highly...

Author:  octopi [ Tue Sep 09, 2003 8:44 pm ]
Post subject: 

msn is 1863, icq is 4000

You will need to impliment such things as a SSL connection...which I doubt turing can handle for msn, and icq will probally be trickier.

Author:  ferrara_999 [ Tue Sep 09, 2003 8:52 pm ]
Post subject:  nm

nm, lol, screw it then

Author:  Tony [ Tue Sep 09, 2003 10:25 pm ]
Post subject: 

I came across a custom MSN client writen in VB... with source code and all...

though it doesnt matter, cuz M$ patched their servers and users are forced to use MSN 5+

Author:  octopi [ Tue Sep 09, 2003 11:04 pm ]
Post subject: 

Your only required to use MSNP9 which is msn's latest protocol for the msn clients.

Its not really that hard to do. Just not posible on turing, but in php, perl, c, c++, it is.


: