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

Username:   Password: 
 RegisterRegister   
 Urgent - Net Help - Multiple connections.
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ashtray13




PostPosted: Sun Jan 19, 2003 11:42 am   Post subject: Urgent - Net Help - Multiple connections.

Anyone know how to make Turing connect to more then one other computer? I wanna make a 5 way chat, i have the idea but it won't connect to anything over 1 computer Sad.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sun Jan 19, 2003 11:49 am   Post subject: (No subject)

to connect to more then 1 computer you need more then 1 StreamNum variables.

so
code:

var netStream : array 1..5 of int
var netAddress : array 1..5 of string %IP addresses
const chatPort :int := 5055

for i:1..5
netStream(i):= Net.OpenConnection(netAddress(i),chatPort)
end for
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
ashtray13




PostPosted: Sun Jan 19, 2003 4:37 pm   Post subject: (No subject)

I accually wanted 5 computers to connect to one place, not 1 to connect to 5 places, is ti possible cause the arrays isn't working, after one time of connecting it just skips.
Tony




PostPosted: Sun Jan 19, 2003 10:44 pm   Post subject: (No subject)

in that case you use an array with Net.WaitForConnection (or something like that)

code:

var netStream:array 1..5 of int

for i:1..5
netStream(i) := Net.WaitForConnection(port+i)
end for


I think this would work...

Though its a better idea to put that into a process so that program can run even if not all 5 clients are connected.

Oh, here's your problem (I think), clients must connect on different ports Very Happy
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Penguin




PostPosted: Mon May 26, 2003 1:50 pm   Post subject: (No subject)

ok, so this would allow all the users that connected to one place to be able to see what each other says to one another? I'm working on a chat program in turing for my summative project. I wanted to have almost like an instat message thing with GUI. Is it possible to have that, or would the "chat room" idea be better? Almost like irc.
Tony




PostPosted: Mon May 26, 2003 2:15 pm   Post subject: (No subject)

instant messaging and chatrooms are practically the same... the only difference is that instant messaging is always talking in private only, while chat is when message is send to all users connected.

they would be structured the same if you plant on sending messages through the server.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Penguin




PostPosted: Mon May 26, 2003 2:30 pm   Post subject: (No subject)

I see, how would I structure it so that my procedures to start a server and allow multiple connections, aswell be able to connect to a server that has multiple users connected which most likely needs to connect to each user on a different port.

procedure waitconnect
put "\N"
put "Your IP Address: ", Net.LocalAddress, " ", "Hostname:", Net.LocalName, "\N"
put "Waiting for other user to connect..." ..
connection := Net.WaitForConnection (PORT, address) % Wait for a user to connect
end waitconnect

%Delares connect procedure
procedure connect
put "\N"
put "Connect to (IP/Hostname:" ..
get address
connection := Net.OpenConnection (address, PORT) % Connect to the IP inputted
end connect
Tony




PostPosted: Mon May 26, 2003 3:25 pm   Post subject: (No subject)

well the server will constantly be listening for a new connection and any incomming messages (all incomming messages are for the server).

if a new connection in made, it is added to an array (you need to figure out a way to disconnect too, so array doesnt overflow).

when a message arrives, it is fawarded to everybody in the array.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
Homer_simpson




PostPosted: Mon May 26, 2003 3:43 pm   Post subject: (No subject)

netwaitconnection command.... i hate that command coz when yer waiting for a connection it doesn't let u do anything else it's like the program freezez untill a connection is made... =(... any idea how to fix that?
hez




PostPosted: Mon May 26, 2003 3:49 pm   Post subject: :D

5-way chat impossible

I am speaking form experience cause i made a 2-way chat prog and only worked with 2 way.

Me and a freind the smartest person in turing (he made an whole os inside win98) Shocked Shocked Shocked Shocked Shocked Shocked
worked togther to make it but it is impossible with turing functionality

toom any problems and network latency is the thing Confused

here is my rough chat code i ripped out of my project ALTER then use it freely if ya want...

it has:
-NICK SUPPORT(WHOO!)
-2-WAY CHAT
-INCOMING SOUNDS
-"QUIT" command
-CLIENT/HOST COLOR

TRY IT OUT Razz Razz Smile Smile Laughing Laughing
there is still some stuff taht shoudn't be inthere like the config.ini stuff delete it
(TEST it out by conenctiong to yuorself (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
%------used to read config.ini file
var config : string
%----for the menu-----
var choice : int
%-----for your nick------
var nick : string := ""
%------for clients nick--------
var nick1 : string
%------To display/log the date-------
var theDateTime, theDate, theTime : string
theDateTime := Time.Date
theDate := theDateTime (1 .. 9)
theTime := theDateTime (11 .. *)
%--------------------------------------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
Tony




PostPosted: Mon May 26, 2003 6:10 pm   Post subject: (No subject)

you cant program an OS in turing... OS interacts between your programs and hardware... what he could have done is made a SHELL based on window's APIs that windows itself is still running Confused
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Penguin




PostPosted: Mon May 26, 2003 6:47 pm   Post subject: (No subject)

lol... hmmmm.... but is it possible. I see there is much argument about that. Has anyone been successful in creating a turing application that can chat to more than one other person at once.
Tony




PostPosted: Mon May 26, 2003 6:56 pm   Post subject: (No subject)

yeah, I had a 3 way chat going back in the day... 1 server, 2 clients... worked well...
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
lil_li




PostPosted: Mon May 26, 2003 6:59 pm   Post subject: (No subject)

can turing really handle all 5 networks at same time?.... i thought turing is too slow Confused
Penguin




PostPosted: Mon May 26, 2003 7:13 pm   Post subject: (No subject)

could the 2 clients see what you were typing both at once. How did it work?
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 2  [ 29 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: