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

Username:   Password: 
 RegisterRegister   
 Internet Chatting
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
FizixMan




PostPosted: Sun Dec 08, 2002 4:07 pm   Post subject: Internet Chatting

I used to talk to a friend of mine through IRC while she was at work, but now they got new firewalls and settings that don't allow her to connect anymore... they have ports 80 and 81 open... I saw a little blurb about someone's netchat program and I was wondering if it works over the internet and if it can be used on those ports...

If not, how can I program one? It would really mean a lot to me 'cause otherwise I can't talk to my close good friend anymore! Crying or Very sad Crying or Very sad Crying or Very sad
Sponsor
Sponsor
Sponsor
sponsor
Dan




PostPosted: Sun Dec 08, 2002 5:17 pm   Post subject: la la la

it is posiable to make a chat progame in turing that runs on port 80, but the problem is i dont think it works over the net (just on netwroks).

but here is the code any way, just chage port to 80 to comiunate over port 80.

code:


%set the screen setings and graphics
setscreen ("Graphics:vga")
setscreen ("Graphics:500;400")

%vars and consts
const port1 : int := 5555 %port to be used
var sorc : string (1)
var data : int
var ip1 : string
var name1 : string
var help : string (1)
var address1 : string
var rowhere : int := 2
var colhere : int := 1
var rowthere : int := maxrow div 2
var colthere : int := 1
var ch : char
var yourip : string
var yourname : string
var madeby:string:="Dan"

cls

%disalp loacl adress
yourip := Net.LocalAddress %get ip
yourname := Net.LocalName %get name
put "Your IP is: ", yourip, "             ", "Your Name is: ", yourname
put ""

%loop to see if conputer is host or not
loop

    %disply choies and input respones
    put "1. Host Chat"
    put "2. Join Chat"
    put "3. Help"
    put "4. Exit"
    put ""
    getch (sorc)

    %creal screen and keep loacl mahine info
    cls
    put "Your IP is: ", yourip, "             ", "Your Name is: ", yourname
    put ""

    %see if exit
    if sorc = "4" then
        cls
        put "Good Bye"
        return %end program

        %if help
    elsif sorc = "3" then
        loop

            %creal screen and keep loacl mahine info
            cls
            put "Your IP is: ", yourip, "             ", "Your Name is: ",
                yourname
            put ""

            %put up help choies and get input
            put "1. Convernt IP to Host Name"
            put "2. Convernt Host Name to IP"
            put "3. Exit Help"
            getch (help)

            % if user picks 1
            if help = "1" then

                %creal screen and keep loacl mahine info
                cls
                put "Your IP is: ", yourip, "             ",
                    "Your Name is: ", yourname
                put ""

                %aks user for ip number and get data
                put "Put in the IP number to convert (EX. 128.100.5.1)"
                put
                    "Note: you need to be onilen or on the nerwrok for this to wrok"
                get ip1

                %out put data
                put ""
                put "Host Name is: ", Net.HostNameFromAddress (ip1)
                delay (3000)

                %if user picks 2
            elsif help = "2" then

                %clera screen and keep loacl mahine info
                cls
                put "Your IP is: ", yourip, "             ",
                    "Your Name is: ", yourname
                put ""

                %ask user for host name
                put "Put in the Host Name to convert (EX. www.yahoo.com)"
                put
                    "Note: you need to be onilen or on the nerwrok for this to wrok"
                get name1

                %output data
                put ""
                put "IP Number is: ", Net.HostAddressFromName (name1)
                delay (3000)

            end if

            %exit when user picks 3
            exit when help = "3"

        end loop

        %creal screen and keep loacl mahine info
        cls
        put "Your IP is: ", yourip, "             ",
            "Your Name is: ", yourname
        put ""

        %resata the meun
        put "1. Host Chat"
        put "2. Join Chat"
        put "3. Help"
        put "4. Exit"
        put ""
    end if

    %exit when user picks 1 or 2
    exit when sorc = "1" or sorc = "2"
end loop

%see if user is host and wait for clint to conect
if sorc = "1" then
    data := Net.WaitForConnection (port1, address1)
    %wait for clint to conect on port 5555

    %see if user is clint and conect to host
else

    %ask user where to conect to
    put "Enter IP or name of conputer to concet to."
    get address1

    %open contection to host
    data := Net.OpenConnection (address1, port1)
    %open contection to host on port 5555
    if data <= 0 then %see if connection was sucesfull
        put "ERROR:01:Unsble to connect to ", address1
        %if it was not then put error mesag
        return %end progame
    end if

end if

%clera screen and keep loacl mahine info
cls
put "Your IP is: ", yourip, "             ", "Your Name is: ", yourname
put ""
put "Connected to ", address1

%trun off echo
setscreen ("noecho")

%loop to send data
loop
    if hasch then

        %get data from key borad and send it
        ch := getchar
        put : data, ch ..

        %if enter is hit then move down line
        if ch = "\n" then %see if enter is hit
            rowhere := rowhere mod (maxrow div 2) + 1 %chage line
            rowthere := 1 %chage line
            colhere := 1
            Text.Locate (rowhere, colhere)
            put "" %clrea line
            %Text.Locate (rowhere, colhere)

            %if it is not an enter and just text
        else
           
            color (brightblue)
            if colhere < maxx - 10 then
                Text.Locate (rowhere, colhere)
                put ch .. %put the text you are typeing
                colhere += 1
            elsif colhere > maxx - 10 then
                rowhere := rowhere mod (maxrow div 2) + 1 %chage line
                rowthere := 1 %chage line
                colhere := 1
                Text.Locate (rowhere, colhere)
                put "" %clrea line
            end if
        end if
    end if

    %geting data from other conputer
    if Net.CharAvailable (data) then %see if there is any thing to get
        get : data, ch %get text form other conputer

        %if enter then move down line
        if ch = "\n" then %see if it is an enter
            rowthere := rowthere mod (maxrow div 2) + 1 + (maxrow div 2)
            colthere := 1
            Text.Locate (rowthere, colthere)
            put "" %ceare line

            %if not enter and just text
        else
            color (brightred)
            if colhere < maxx - 10 then
                Text.Locate (rowthere, colthere)
                put ch .. %put text form other conputer
                colthere += 1
            elsif colhere > maxx - 10 then
                rowthere := rowthere mod (maxrow div 2) + 1 + (maxrow div 2)
                colthere := 1
                Text.Locate (rowthere, colthere)
                put "" %ceare line
            end if
        end if
    end if
end loop


sory about the spacing it may be a bit off


also if you whont to tlak to your frend there are a lot of chat progames out there that will let you slect a port to use.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
WooFerPPK




PostPosted: Sun Dec 08, 2002 5:55 pm   Post subject: (No subject)

sorry if you didnt want me to edit this but i modifed the code and it works over the net. Im very VERY close to finding the problem with the missing characters. I almost got it to, just for some reason the after a few msg's the msg screws up and somtimes doesnt apear. When i fiqure it out ill send it to u guys.

code:
View.Set ("graphics:670;368,nobuttonbar")
colorback (black)
cls

var port : int := 007
var sorc, help, leave : string (1)
var data : int
var ip, name, address, yourip : string
var rowhere : int := 2
var colhere : int := 1
var rowthere : int := maxrow div 2
var colthere : int := 1
var ch : char


% Shows Ip address
yourip := Net.LocalAddress
color (10)
put "Your IP is: ", yourip
put ""

% Help, Host, Join, change, or exit program
loop

    color (yellow)
    % Menu
    put "1: Host Chat"
    put "2: Join Chat"
    put "3: Help"
    put "4: Change Port"
    put "5: Exit"
    put ""
    getch (sorc)


    cls
    color (10)
    put "Your IP is: ", yourip
    put ""

    %see if exit
    if sorc = "5" then
        cls
        color (0)
        locate (11, 21)
        put "Thank you for using my program"
        return
    end if

    if sorc = "4" then
        color (0)
        put "Type in the port number (max 99999)"
        get port
        put "Press E to exit"
        getch (leave)
        cls
    end if

    if sorc = "3" then
        loop
            color (10)
            cls
            put "Your IP is: ", yourip
            put ""

            %put up help choies and get input
            color (yellow)
            put "Help area"
            put ""
            put "1: How to use program"
            put "2: Defenition of IP"
            put "3: How the ports system works"
            put "4: Exit Help"
            getch (help)

            % if user picks 1
            if help = "1" then
                cls
                put "What this program does is send and recive messages using turing"
                put "You are ether a host or a joiner. A host makes there computer a server"
                put "The joiner join's the host's server to chat with. This program DOESNT"
                put "require you to be on a network."
                put ""
                put "Press e to exit help"
                getch (help)
                exit when help = "e"

            elsif help = "2" then
                cls
                put "IP by itself is something like the postal system. It allows you to address "
                put "a package and drop it in the system, but there's no direct link between"
                put "you and the recipient. TCP/IP, on the other hand, establishes a connection"
                put "between two hosts so that they can send messages back and forth for a "
                put "period of time"
                put ""
                put "Press e to exit help"
                getch (help)
                exit when help = "e"

            elsif help = "3" then
                cls
                put "Ports is like a TV. There is 1 tv but there are differnt channels"
                put "With ports you can flip differnt channels. So if i want to talk to bob"
                put "Bob would be on port 1. Port 1 is now in use. Now joe wants to talk to me"
                put "well you give joe your ip, and you tell joe to use his port number 2."
                put "you can use the same computer with the same address and talk to two differnt"
                put "people"
                put ""
                put "Press e to exit"
                getch (help)
                exit when help = "e"
            end if

            exit when help = "4"
        end loop


        cls
        color (10)
        put "Your IP is: ", yourip
        put ""
    end if

    exit when sorc = "1" or sorc = "2"
end loop

% This will wait for the user to connect if you are a host
if sorc = "1" then
    data := Net.WaitForConnection (port, address)

else

    % This asks the user what is the ip of the computer to connect to
    put "Enter IP of conputer to concet to."
    get address

    % This will open a connection for the host so the "Joiner" can join into your server
    data := Net.OpenConnection (address, port)

    % This will produce an Error message if it was unable to successfully connect
    if data <= 0 then
        color (12)
        put "Unable to connect to ", address

        return
    end if

end if

% This will show up if you successfuly connect
cls
color (10)
put "Your IP is: ", yourip
color (yellow)
put "You are connected to", address


% This is the main part, this will send and recive the text the user is getting
loop
    if hasch then

        % This will allow you to actuly type stuff on the keyboard
       get ch
        % ch := getchar
        put : data, ch ..

        % If enter is hit this will make both users move down a line
        if ch = "\n" then
            rowhere := rowhere mod (maxrow div 2) + 1
            rowthere := 1
            colhere := 1
            Text.Locate (rowhere, colhere)
            put ""

        else
            % This will show you the text that you are typing
            color (brightblue)
            if colhere < maxx - 10 then
                Text.Locate (rowhere, colhere)
                put ch ..
                colhere += 1


            elsif colhere > maxx - 10 then
                rowhere := rowhere mod (maxrow div 2) + 1
                rowthere := 1
                colhere := 1
                Text.Locate (rowhere, colhere)
                put ""
            end if
        end if
    end if
    color (brightred)

    % This will keep the data in till the user presses enter
    if Net.LineAvailable (data) then
        var line : string
        get : data, line : *
        put line
    end if
end loop
Tony




PostPosted: Sun Dec 08, 2002 6:17 pm   Post subject: (No subject)

I've heard from Martin that because of the way Net was build in turing, some characters @ the beginning of the string might get cut off.

If thats the case, what you do to fix the problem is send a message with " " added in front of the message and once recieved, you just check for first character. If its a " " you just remove it put line(2..*)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Dan




PostPosted: Sun Dec 08, 2002 6:39 pm   Post subject: (No subject)

you can download my verion of the net chat progame form ftp://swat@danco.no-ip.com/Turing/Turing%20Programs/Turing%20Chat/netchat.zip
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
FizixMan




PostPosted: Mon Dec 09, 2002 11:06 pm   Post subject: (No subject)

Thanks for your help and immediate response guys, I really appreciate it. Though I never had a chance to test the program with my friend 'cause the firewall changed again at her work and now IRC is working again. But again thanks anyways... at least now I got the program and if it happens again we can test it. Very Happy Very Happy
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: