Computer Science Canada

[source code] The best and the only chat....

Author:  hez [ Mon May 26, 2003 3:52 pm ]
Post subject:  [source code] The best and the only chat....


This is just part pf my chat code from my last semester project

(i didn't include filetransfer, port scanner and advnced features srry)

hope you like it Razz

It has:

-"QUIT" command

(TEST by runnig 2 instances & connecting to(

%-------------------------------------------START MAIN CHAT MODULE---------------------
%--------------OPEN NEW WINDOW=-------------
var window : int
window := Window.Open ("title:Chat Main By:Hez,graphics:700;200,nobuttonbar,position:center;center")

%-------------------VERY IMPORTANT CHAT-MODULE VARIABLES--------------
var setok : int := 0
%---PORT to conenct to---
var p1 : int := 28000
%----for the menu-----
var choice : int
%-----for your nick------
var nick : string := ""
%------for clients nick--------
var nick1 : string

    locate (3, 1)
    put "Your TCP/IP Adress: ", Net.LocalAddress, " on ", Net.LocalName
    put "1 -- Host a Chat Server"
    put "2 -- Join an Existing Chat Server"
    put "3 -- Quit Chat"
    put "Selection: " ..
    get choice
    exit when choice = 1 or choice = 2 or choice = 3
end loop

%-------To OPen 2-way conenctions
var netStream, netStream2 : int := 0
%------------To store ip in
var netAddress : string := ""
%---------------mi=HOST COLOR TEXT / mo=CLIENT COLOR TEXT
var mi : int := 1
var mo : int := 2

%--------BACK SOUND~---
process rec
    play ("aabb")
end rec

%----------------------------SET UP CONFIG.INI FILE WITH BINARY/TEXT------------

procedure setall ()

    var c1 : string

    put "Enter Nick.."
    get nick
    nick1 := nick + " : "

end setall

procedure setall2 ()
    var c1 : string
    put "Enter Nick.."
    get nick
    nick1 := nick + " : "
    put "Enter the (HOST) address to connect to: " ..
    get c1

    netAddress := c1

end setall2
%important ip storing variable...
var ip : string

procedure start ()
    %---------GETTING READY TO CHAT-------------------------
    var hostAddr : string := netAddress

    %--------------------------------------MAIN CHAT----------------------
    %--------VARIABLES for storing /loging text written 2-way
    var ch1, ch2 : string
    var str : string
    str := ""
    View.Set ("noecho")
    %--------------------------new window-----------------------------
    var inp : int
    inp := Window.Open ("title:Chat,position:center;center,graphics:500;500")
    Window.Close (window)

    %--------------------------------------CHAT STUFF----------------------
    put "You Are Chatting With ->", netAddress, ":", p1
    put "Hostname: ", Net.HostNameFromAddress (hostAddr)
    put "TYPE QUIT to quit"
    put "On: ", Time.Date
    for i : 1 .. 62
        put "-" ..
    end for
    put ""
    put ""

    %-----------DELAY to Verify stability for conenction---------
    for i : 1 .. 10
        put "Verifying connection... ", i
        delay (500)
        locate (whatrow - 1, 1)
        put "                                "
        locate (whatrow - 1, 1)
    end for
    %-----------sound of verification-------------
    play ("8aaaabbbbaaaaaa")

    %---------------------START CHATTING----MAIN MODULE------------
        %--------------GET READY TO SEND TEXT IF KEY AVAILABLE-----------
        if hasch then
            Window.Select (inp)
            get ch1 : *
            put : netStream, nick1 + ch1

            locate (whatrow - 1, 1)
            color (mi)
            put nick1, ch1, str
            %----------------QUIT TELLS THE 2nd USER YOU HAVE DISCONNECTED------------
            if ch1 = "quit" then
                put : netStream, nick, ", ( ", Net.LocalAddress, " )", "has Disconnected.."
                Window.Close (inp)
            end if
        end if
        %------------------------CHECKS EVERYTIME FOR NEW LINE------------------------
        if Net.LineAvailable (netStream) then
            get : netStream, ch2 : *
            color (mo)
            put ch2, str
            fork rec
        end if

    end loop

    %---------------------------------------------------ENDCHAT MODULE------------------------------------

end start

%--------------------------------------SERVER SETUP----------------------
if choice = 1 then

    setall ()
    put "Waiting for incoming conenctions..."
    put "Your Hosting Address => ", Net.LocalAddress, ":", p1
    netStream := Net.WaitForConnection (p1, netAddress)
    put ""
    put ""
    start ()
end if

if choice = 2 then

    setall2 ()

    put "The Host be Ready To Accept your connection..."
    put "Conncting in 5 secs.. Please Wait.."
    delay (5000)

    netStream := Net.OpenConnection (netAddress, p1)
    if netStream <= 0 then
        put "Unable to connect to ", netAddress
    end if
    start ()

elsif choice = 3 then
    %-------------GET READY TO QUIT-----------
end if

Author:  PaddyLong [ Sat May 31, 2003 12:57 pm ]
Post subject: 

how can you run two instances?

Author:  Tony [ Sat May 31, 2003 1:12 pm ]
Post subject: 

i'd say compile the code and open file two times.

Author:  PaddyLong [ Sat May 31, 2003 1:15 pm ]
Post subject: 

I tired that but when I try to compile it it says no dice because this version doesn't have that capabilities... it's the turing 4.01p from the turing submissions section

Author:  Tony [ Sat May 31, 2003 1:27 pm ]
Post subject: 

you gotta get the patch to upgrade to v4.0.4[random letter]

go to and look for it

Author:  Homer_simpson [ Sat May 31, 2003 1:33 pm ]
Post subject: 

very nice...Very Happy
the only thing that it needs is a cool gui output..
I'd donate bits but yer the admin...=Þ

Author:  Tony [ Sat May 31, 2003 1:52 pm ]
Post subject: 

huh, its hez's program, not mine Confused

Author:  Homer_simpson [ Sat May 31, 2003 2:30 pm ]
Post subject: 

oh oops Embarassed
here u go hez have some bits...
+10 bits to hez
make a nice gui for it and i'll give u some more bits

Author:  Mephi [ Sat May 31, 2003 2:43 pm ]
Post subject: 

isnt there one of those in truing examples? i dunno, but i remember seeing it...

Author:  PaddyLong [ Sat May 31, 2003 2:50 pm ]
Post subject: 

ok thanks for the informations on updating the Turing to the new version

Author:  Homer_simpson [ Sat May 31, 2003 3:14 pm ]
Post subject: 

there is a chat example in turing but i dont think hez has used that...

Author:  Chimaera [ Mon Oct 20, 2003 1:35 pm ]
Post subject: 

How would you be able to modify the program to have multi-way chat and 1 host? I'm trying to get it to be able to have 1 computer to host and have multiple clients connect to the same host but so far it doesn't make sense to me as to how I can get 2+ computers onto the same connection.

Author:  Andy [ Sun Nov 09, 2003 5:28 pm ]
Post subject: 

i dont think what ur trying to do is possible... however, what u can do is have everybody connect to one comp and send all messages to that comp then from that comp send the message out to everybody. gonna take a lot of work to pull this one off, post it here if u manage to get it working

Author:  Chimaera [ Mon Nov 10, 2003 8:56 pm ]
Post subject: 

How would one get that to work? Considering the source code posted above is supposed to work on that principle of having 1 host and 1 client, the idea of a relaying the messages to alternate clients doesn't go through. My friends and I tried to use this program to have more than 2 people per chat but they could join, type stuff in but it wouldn't get sent to us so what you guys suggested doesn't seem to work. Perhaps it's just me XD

Author:  Catalyst [ Mon Nov 10, 2003 9:16 pm ]
Post subject: 


Author:  Chimaera [ Mon Nov 10, 2003 10:26 pm ]
Post subject: 

well one of the resident Turing geniuses hath spoken. Fork it is.

Author:  rizzix [ Tue Nov 11, 2003 4:50 pm ]
Post subject: 

Chimaera wrote:
How would you be able to modify the program to have multi-way chat and 1 host? I'm trying to get it to be able to have 1 computer to host and have multiple clients connect to the same host but so far it doesn't make sense to me as to how I can get 2+ computers onto the same connection.

it is really easy.. u need to know a bit on networking. well now for this app u cannot use a peer2peer design (actually u can but then it gets Very Complicated). so now u need a client server design.. this way all the clients register themselves with the server (i.e they logon). then the server sends a list of all available contacts (online folks). when a client initiates a conversaion with one of them it really tell the server to notify the other client about it.

from this step onwards u get a choice:
1) send all messages through the server to the other client and visa-versa
2) initiate a direct connection with the other client by using the information provided by the server. then both clients connect to one another..

for a group conversation u'll need to use choice 1 only.

a pooling mechanism is necessary on the server side for choice 1

Author:  white_dragon [ Tue Jan 13, 2004 6:15 pm ]
Post subject: 

i really liked it. nice work on da whole ting. all da other chat programs didn't work on my compu. Very Happy urs did. good job!

Author:  shorthair [ Tue Jan 13, 2004 6:40 pm ]
Post subject: 

its good BUT definatly not hte best , neither is mine but here are a few things in mine that you should consider intagrating into yours , i have edited a proper email function that stops overflows on line , so that whe na picture loads it wont error out , hte only thing that cant be fixed is somtimes you get a integer overflow expression for some reason , and you can sufeccfully connect to an ftp with mine and send commands to it , you cant do that on yours becuase no matter what he sends your nick name with the message , when you go to ftp or email on mine , you nick name gets cut out., so really its 3 programs in one, dont call it the best chat program ever man , there is along way to go before its the on a lighter note your use of verifing the integrity was a good idea i like it , your program was good so il give you some bits but dont think its the only one out there... Very Happy Very Happy

+ bits

Author:  icemaster [ Wed Jan 14, 2004 10:58 am ]
Post subject: 

8) 8)
wow sounds tricky, what if i told you it has already been done.... haha
are you ready? Shocked 8)