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

Username:   Password: 
 RegisterRegister   
 [source code] The best and the only chat....
Index -> Programming, Turing -> Turing Submissions
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
hez




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

hi....

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:

-NICK SUPPORT
-2-WAY CHAT
-INCOMING SOUNDS
-"QUIT" command
-CLIENT/HOST COLOR

(TEST by runnig 2 instances & connecting to(127.0.0.1))
code:



%-------------------------------------------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--------------
%------0 = NO PROFILE SET 1= PROFILE SET
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
%--------------------------------------MENU----------------------

loop
    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

%--------------------------------------VARIABLES----------------------
%-------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 + " : "
    cls
    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----------------------
    Draw.Cls
    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------------
    loop
        %--------------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)
                exit
            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
    cls

    setall ()
    cls
    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
    cls

    setall2 ()
    cls

    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
        return
    end if
    start ()

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


Sponsor
Sponsor
Sponsor
sponsor
PaddyLong




PostPosted: Sat May 31, 2003 12:57 pm   Post subject: (No subject)

how can you run two instances?
Tony




PostPosted: Sat May 31, 2003 1:12 pm   Post subject: (No subject)

i'd say compile the code and open file two times.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
PaddyLong




PostPosted: Sat May 31, 2003 1:15 pm   Post subject: (No 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
Tony




PostPosted: Sat May 31, 2003 1:27 pm   Post subject: (No subject)

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

go to www.holtsoft.com and look for it
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Homer_simpson




PostPosted: Sat May 31, 2003 1:33 pm   Post subject: (No subject)

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




PostPosted: Sat May 31, 2003 1:52 pm   Post subject: (No subject)

huh, its hez's program, not mine Confused
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Homer_simpson




PostPosted: Sat May 31, 2003 2:30 pm   Post subject: (No 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
Mephi




PostPosted: Sat May 31, 2003 2:43 pm   Post subject: (No subject)

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




PostPosted: Sat May 31, 2003 2:50 pm   Post subject: (No subject)

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




PostPosted: Sat May 31, 2003 3:14 pm   Post subject: (No subject)

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




PostPosted: Mon Oct 20, 2003 1:35 pm   Post subject: (No 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.
Andy




PostPosted: Sun Nov 09, 2003 5:28 pm   Post subject: (No 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
Chimaera




PostPosted: Mon Nov 10, 2003 8:56 pm   Post subject: (No 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
Catalyst




PostPosted: Mon Nov 10, 2003 9:16 pm   Post subject: (No subject)

fork
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 20 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: