Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [tutorial]Chat Program
Index -> Programming, Turing -> Turing Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Delta




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Blade




PostPosted: Sat Mar 22, 2003 12:16 am   Post subject: (No 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
Delta




PostPosted: Sat Mar 22, 2003 12:59 am   Post subject: (No 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
leepham




PostPosted: 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
Tony




PostPosted: Mon Mar 24, 2003 4:36 pm   Post subject: (No 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Miyoko




PostPosted: Mon Mar 31, 2003 1:30 pm   Post subject: (No 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
Delta




PostPosted: Mon Mar 31, 2003 2:03 pm   Post subject: (No subject)

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




PostPosted: 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)
Sponsor
Sponsor
Sponsor
sponsor
Homer_simpson




PostPosted: Tue Sep 09, 2003 4:55 pm   Post subject: (No subject)

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




PostPosted: Tue Sep 09, 2003 8:44 pm   Post subject: (No 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.
ferrara_999




PostPosted: Tue Sep 09, 2003 8:52 pm   Post subject: nm

nm, lol, screw it then
Tony




PostPosted: Tue Sep 09, 2003 10:25 pm   Post subject: (No 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+
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
octopi




PostPosted: Tue Sep 09, 2003 11:04 pm   Post subject: (No 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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: