Computer Science Canada

Networked Instant Messenger, Multi User Help.

Author:  Miketron [ Wed Jan 10, 2007 11:43 pm ]
Post subject:  Networked Instant Messenger, Multi User Help.

Alright, I've been working on this for a fair while and it was working properly until I hit a bit of a bump. The messenger wasn't multi user, so I have now attempted to make it able to run up to 10 users. For some reason it is not working, and if anyone would help me out I would be very greatful. It's probably something very simple but I cannot put my finger on it. The error you get is that it the stream is found to have no value when it goes to retrieve a message and prior to adding the arrays, it worked with a singlr stream.



import GUI
setscreen ("graphics:400;500,nobuttonbar,inttitle:Turing Messenger")
View.Update
colourback (54)
cls

var port : int
port := 5505

procedure clearlines

locate (1, 1)
put "" : 40
locate (2, 1)
put "" : 40
locate (3, 1)
put "" : 40
locate (4, 1)
put "" : 40
locate (5, 1)
put "" : 40
locate (6, 1)
put "" : 40

end clearlines

%--------Networking-----------
var strNetAddress : string
var stream : array 1 .. 10 of int
var intchoice : int
var strchoice : string (1)

%--------Message--------------
var strmessage : string
var strmessagetemp : string
var strmessagecloak : string

%--------Names----------------
var strname : string
var strstreamname : string

%--------TextBox--------------
var inttextbox : int
var inttitle : int

%--------MessageBox-----------
inttitle := GUI.CreateLabelFull (20, 280, "Messages", 250, 0, GUI.CENTER, 0)
inttextbox := GUI.CreateTextBoxFull (10, 10, 280, 265, GUI.INDENT, 0)

%--------Frame----------------
var startframe : int
var Hosty : int
var Joiny : int
var Host : int
var Join : int

%--------Server---------------
var servertitle : int
var servertextbox : int

servertitle := GUI.CreateLabelFull (330, 280, "Servers", 150, 0, GUI.CENTER, 0)
servertextbox := GUI.CreateTextBoxFull (320, 10, 180, 265, GUI.INDENT, 0)

var SERVER : boolean
var USERS : int := 0

%--------MessageReset---------
var resetcounter : int
resetcounter := 0

procedure DoNothing (text : string)
end DoNothing

procedure host

GUI.Dispose (startframe)
GUI.Dispose (Hosty)
GUI.Dispose (Joiny)
GUI.Dispose (Host)
GUI.Dispose (Join)
cls
GUI.Refresh

put "Chat started", Net.LocalAddress
put "Waiting for connection..."
stream (1) := Net.WaitForConnection (port, strNetAddress)
USERS := USERS + 1
strstreamname := strname
SERVER := true
GUI.Quit

end host

procedure join

GUI.Dispose (startframe)
GUI.Dispose (Hosty)
GUI.Dispose (Joiny)
GUI.Dispose (Host)
GUI.Dispose (Join)
cls
GUI.Refresh

put "Host Address: "
get strNetAddress
stream (1) := Net.OpenConnection (strNetAddress, port)
if stream (1) <= 0 then
put "Failure connecting to host, ", strNetAddress
return
else
put "Connected to ", strNetAddress
end if

SERVER := false

GUI.Quit

end join

process chat

loop

if resetcounter >= 6 then
clearlines
locate (1, 1)
resetcounter := 0
end if

get strmessage : *

resetcounter := resetcounter + 1

if strmessage not= "" then

strmessagetemp := strmessage

put : stream (1), strname, ": ", strmessagetemp

strmessagecloak := strname + ": " + strmessagetemp

GUI.AddLine (inttextbox, strmessagecloak)

end if
end loop

end chat

process NewClients

loop
port := port + USERS
if USERS < 10 then
stream (USERS) := Net.WaitForConnection (port, strNetAddress)
USERS := USERS + 1
end if
end loop

end NewClients

process recieve

loop

for i : 1 .. 10

if Net.CharAvailable (stream (i)) then

get : stream (i), strmessagecloak : *

if strmessagecloak not= "" then

GUI.AddLine (inttextbox, strmessagecloak)

end if

end if

end for
end loop

end recieve

put "Welcome to the Mike's chat"
put "Please enter your name: "
get strname : *

port := port + USERS

cls
GUI.Refresh

startframe := GUI.CreateLabelledFrame (10, 390, 293, 300, GUI.INDENT, "Chat")
Hosty := GUI.CreateLabel (55, 360, "Click the Host button to host a chat.")
Joiny := GUI.CreateLabel (55, 370, "Click the join button to join a chat.")
Host := GUI.CreateButton (55, 330, 0, "Host Chat", host)
Join := GUI.CreateButton (160, 330, 0, "Join Chat", join)

loop
exit when GUI.ProcessEvent
end loop

cls
GUI.Refresh

loop
delay (2000)
fork chat
fork recieve

if SERVER = true then
fork NewClients
end if

end loop


Author:  rdrake [ Wed Jan 10, 2007 11:55 pm ]
Post subject:  Re: Networked Instant Messenger, Multi User Help.

I recken you will need to write a quick server application. The server will accept connections from the clients, and receive messages from the clients. Once a message is received, the server will send the message out to all clients.

Doing this in a centralized way will simplify things greatly.

Author:  Miketron [ Thu Jan 11, 2007 9:51 am ]
Post subject:  Re: Networked Instant Messenger, Multi User Help.

Is it possible to work through an individual client like this? Or do I absolutely NEED to have a server application aswell? I've seen coding for a server based messenger, but I would prefer to have it in a single client that can act as a message window aswell as the actual server.

Author:  rdrake [ Thu Jan 11, 2007 10:29 am ]
Post subject:  Re: Networked Instant Messenger, Multi User Help.

It is possible, you just need to have a client designate itself as the server. This way it still relays the messages to other clients, but it also acts as a client in the process.

A centralized server-based method would be much simpler, though it is possible to do otherwise.

Author:  Miketron [ Thu Jan 11, 2007 10:53 am ]
Post subject:  Re: Networked Instant Messenger, Multi User Help.

Alright, I have taken your advice and have started making a small server based messenger but in the process of cleaning up the client, I have hit yet another pot hole. When I added GUI text fields, it now will not let me type. The code is as follows


import GUI
setscreen ("graphics:400;500,nobuttonbar,inttitle:Turing Messenger")
View.Update
colourback (54)
cls

var port : int := 5505

%--------Networking-----------
var strNetAddress : string
var stream : array 1 .. 10 of int

%--------Message--------------
var strmessage : string
var strmessagetemp : string
var strmessagecloak : string

%--------Names----------------
var strname : string
var strstreamname : string

%--------MessageBox--------------
var inttextbox : int
var inttitle : int
inttitle := GUI.CreateLabelFull (20, 280, "Messages", 250, 0, GUI.CENTER, 0)
inttextbox := GUI.CreateTextBoxFull (10, 10, 280, 265, GUI.INDENT, 0)

%--------Frame----------------
var startframe : int
var Joiny : int
var Join : int

%--------Server---------------
var USERS : int := 0
var ip1 : int
var ip2 : int
var ipl : int
var ipsend : int

%--------MessageReset---------
var resetcounter : int
resetcounter := 0

procedure clearlines

locate (1, 1)
put "" : 40
locate (2, 1)
put "" : 40
locate (3, 1)
put "" : 40
locate (4, 1)
put "" : 40
locate (5, 1)
put "" : 40
locate (6, 1)
put "" : 40

end clearlines

procedure DoNothing (text : string)
end DoNothing

procedure ipz
strNetAddress := GUI.GetText (ip2)
GUI.Disable (ip2)
end ipz

procedure name
strname := GUI.GetText (ip1)
GUI.Disable (ip1)

end name

procedure join

GUI.Dispose (Joiny)
GUI.Dispose (Join)
cls
GUI.Refresh
Joiny := GUI.CreateLabel (55, 370, "Please enter the ip below, and press enter.")
ip2 := GUI.CreateTextFieldFull (105, 345, 100, "", DoNothing, GUI.INDENT, 0, 0)
ipsend := GUI.CreateButton (125, 310, 0, "Enter", ipz)

loop
exit when GUI.ProcessEvent
end loop

stream (1) := Net.OpenConnection (strNetAddress, port)

if stream (1) <= 0 then
put "Failure connecting to host, ", strNetAddress
return
else
put "Connected to ", strNetAddress
end if

GUI.Quit

end join

process chat

loop

if resetcounter >= 6 then
clearlines
locate (1, 1)
resetcounter := 0
end if

get strmessage : *

resetcounter := resetcounter + 1

if strmessage not= "" then

strmessagetemp := strmessage

put : stream (1), strname, ": ", strmessagetemp

strmessagecloak := strname + ": " + strmessagetemp

GUI.AddLine (inttextbox, strmessagecloak)

end if
end loop

end chat

process NewClients

loop
if USERS < 10 then
stream (USERS) := Net.WaitForConnection (port, strNetAddress)
USERS := USERS + 1
end if
end loop

end NewClients

process recieve

loop

for i : 1 .. 10

if Net.CharAvailable (stream (i)) then

get : stream (i), strmessagecloak : *

if strmessagecloak not= "" then

GUI.AddLine (inttextbox, strmessagecloak)

end if

end if

end for
end loop

end recieve

startframe := GUI.CreateLabelledFrame (10, 390, 293, 300, GUI.INDENT, "Chat")
Joiny := GUI.CreateLabel (55, 370, "Welcome to the chat, Enter your name.")
ip1 := GUI.CreateTextFieldFull (105, 345, 100, "", DoNothing, GUI.INDENT, 0, 0)
ipsend := GUI.CreateButton (125, 310, 0, "Enter", name)

loop
exit when GUI.ProcessEvent
end loop

cls
GUI.Refresh
Joiny := GUI.CreateLabel (55, 370, "Click the join button to join a chat.")
Join := GUI.CreateButton (105, 330, 0, "Join Chat", join)

loop
exit when GUI.ProcessEvent
end loop

cls
GUI.Refresh

loop
delay (2000)
fork chat
fork recieve
end loop

Author:  rdrake [ Thu Jan 11, 2007 8:46 pm ]
Post subject:  Re: Networked Instant Messenger, Multi User Help.

Unfortunately Turing (4.0.5c) crashes when I try to run your code. Though I suspect the issue has something to do with the following line.
code:
ip2 := GUI.CreateTextFieldFull (105, 345, 100, "", DoNothing, GUI.INDENT, 0, 0)
I have absolutely idea why it calls a procedure that does nothing at all...

Just a few other nitpicks:

  • Variable names and method/procedure/function names start with a lowercase letter. They can either be in [c]thisStyle[/c] or [c]this_style[/c], it's your choice. Just keep your choice consistant. Names of classes usually start with capital letters, though.
  • Please indent your code. If you press F2, Turing will do it for you.
  • [code ] and [/code ] tags are an excellent idea, minus the spaces of course.


Sorry I can't help more, like I said, Turing gives me an "Access Violation" error when I try running your code.

Author:  Ultrahex [ Thu Jan 11, 2007 9:20 pm ]
Post subject:  Re: Networked Instant Messenger, Multi User Help.

Ok it appears as though line 26 is causing the error

Turing:

inttextbox := GUI.CreateTextBoxFull (10, 10, 280, 265, GUI.INDENT, 0)


if you comment them the program works fine... (well except that textbox is not there)

it appears as though you cant create the CreateTextBoxFull before your GUI.CreateTextFieldFull ... im not sure why this is, hopefully someone could figure this out in turing.

Hope This Helps.

Author:  Miketron [ Thu Jan 11, 2007 10:21 pm ]
Post subject:  Re: Networked Instant Messenger, Multi User Help.

Ah thank you for the help, I just loaded the text boxes after the buttons and it now works.


P.S My teacher doesn't know anything about the network functions of turing, and more than basic GUI. For some reason the program skips the second button, likely assuming that it has processed it's event.

Thank you all again for the help.

code:

import GUI
setscreen ("graphics:400;500,nobuttonbar,inttitle:Turing Messenger")
View.Update
colourback (54)
cls

var port : int := 5505

%--------Networking-----------
var netaddress : string
var stream : array 1 .. 10 of int

%--------Message--------------
var strmessage : string
var strmessagetemp : string
var strmessagecloak : string

%--------Names----------------
var strname : string

%--------MessageBox--------------
var inttextbox : int
var inttitle : int
%--------Frame----------------
var startframe : int
var joiny : int
var join : int
var joiny2 : int
var join2 : int
var ip1 : int
var ip2 : int
var ipl : int
var ipsend : int

%--------MessageReset---------

var resetcounter : int
resetcounter := 0

procedure clearlines

    locate (1, 1)
    put "" : 40
    locate (2, 1)
    put "" : 40
    locate (3, 1)
    put "" : 40
    locate (4, 1)
    put "" : 40
    locate (5, 1)
    put "" : 40
    locate (6, 1)
    put "" : 40

end clearlines

procedure DoNothing (text : string)
end DoNothing

procedure ipz
    netaddress := GUI.GetText (ip2)
    GUI.Disable (ip2)
end ipz

procedure name
    strname := GUI.GetText (ip1)
    GUI.Quit
end name

procedure Join

    GUI.Dispose (joiny)
    GUI.Dispose (join)
    joiny := GUI.CreateLabel (55, 370, "Please enter the ip below, and press enter.")
    ip2 := GUI.CreateTextFieldFull (105, 345, 100, "", DoNothing, GUI.INDENT, 0, 0)
    ipsend := GUI.CreateButton (125, 310, 0, "Enter", ipz)

    loop
        exit when GUI.ProcessEvent
    end loop

    stream (1) := Net.OpenConnection (netaddress, port)

    if stream (1) <= 0 then
        put "Failure connecting to host, ", netaddress
        return
    else
        put "Connected to ", netaddress
    end if

    GUI.Quit

end Join

process chat

    loop

        if resetcounter >= 6 then
            clearlines
            locate (1, 1)
            resetcounter := 0
        end if

        get strmessage : *

        resetcounter := resetcounter + 1

        if strmessage not= "" then

            strmessagetemp := strmessage

            put : stream (1), strname, ": ", strmessagetemp

            strmessagecloak := strname + ": " + strmessagetemp

            GUI.AddLine (inttextbox, strmessagecloak)

        end if
    end loop

end chat


process recieve

    loop

        for i : 1 .. 10

            get : stream (i), strmessagecloak : *

            if strmessagecloak not= "" then

                GUI.AddLine (inttextbox, strmessagecloak)

            end if


        end for
    end loop

end recieve

startframe := GUI.CreateLabelledFrame (10, 390, 293, 300, GUI.INDENT, "Chat")
joiny := GUI.CreateLabel (55, 370, "Welcome to the chat, Enter your name.")
ip1 := GUI.CreateTextFieldFull (105, 345, 100, "", DoNothing, GUI.INDENT, 0, 0)
ipsend := GUI.CreateButton (125, 310, 0, "Enter", name)
inttitle := GUI.CreateLabelFull (20, 280, "Messages", 250, 0, GUI.CENTER, 0)
inttextbox := GUI.CreateTextBoxFull (10, 10, 280, 265, GUI.INDENT, 0)

loop
    exit when GUI.ProcessEvent
end loop

cls
GUI.Refresh
GUI.Dispose (joiny)
GUI.Dispose (ipsend)
GUI.Dispose (ip1)


joiny2 := GUI.CreateLabel (55, 370, "Click the join button to join a chat.")
join2 := GUI.CreateButton (105, 330, 0, "Join Chat", Join)

loop
    exit when GUI.ProcessEvent
end loop

cls
GUI.Refresh

loop
    delay (2000)
    fork chat
    fork recieve
end loop

Author:  Ultrahex [ Thu Jan 11, 2007 11:00 pm ]
Post subject:  Re: Networked Instant Messenger, Multi User Help.

Ok, i was going through your code a little bit, and there is some things you need to fix up cause of this bug, it will happen again with the code you have in your Join procedure. what you need to do is make all your buttons and all that GUI at one point in the program, then hide and show your GUI buttons. This is probably the easier way to get out of this bug happening.

also when you Dispose of stuff Remeber use the following code after:
code:
cls %Clears Screen
GUI.Refresh %Refreshes GUI
GUI.ResetQuit %Turns GUI.ProcessEvent back to False


(BTW next time you paste your code you could use the tags, when you post just hit more tags, then its code and hit code again to close
Here is your code a little bit farther:
code:
import GUI
setscreen ("graphics:400;500,nobuttonbar,inttitle:Turing Messenger")
View.Update
colourback (54)
cls

var port : int := 5505

%--------Networking-----------
var netaddress : string
var stream : array 1 .. 10 of int

%--------Message--------------
var strmessage : string
var strmessagetemp : string
var strmessagecloak : string

%--------Names----------------
var strname : string

%--------MessageBox--------------
var inttextbox : int
var inttitle : int
%--------Frame----------------
var startframe : int
var joiny : int
var join : int
var joiny2 : int
var join2 : int
var ip1 : int
var ip2 : int
var ipl : int
var ipsend : int

%--------MessageReset---------

var resetcounter : int
resetcounter := 0

procedure clearlines

    locate (1, 1)
    put "" : 40
    locate (2, 1)
    put "" : 40
    locate (3, 1)
    put "" : 40
    locate (4, 1)
    put "" : 40
    locate (5, 1)
    put "" : 40
    locate (6, 1)
    put "" : 40

end clearlines

procedure DoNothing (text : string)
end DoNothing

procedure ipz
    netaddress := GUI.GetText (ip2)
    GUI.Disable (ip2)
end ipz

procedure name
    strname := GUI.GetText (ip1)
    GUI.Quit
end name

procedure Join

    GUI.Dispose (joiny2)
    GUI.Dispose (join2)
   
    ip2 := GUI.CreateTextFieldFull (105, 345, 100, "", DoNothing, GUI.INDENT, 0, 0)
    ipsend := GUI.CreateButton (125, 310, 0, "Enter", ipz)
    joiny := GUI.CreateLabel (55, 370, "Please enter the ip below, and press enter.")
    cls
    GUI.Refresh
    GUI.ResetQuit
    loop
        exit when GUI.ProcessEvent
    end loop

    stream (1) := Net.OpenConnection (netaddress, port)

    if stream (1) <= 0 then
        put "Failure connecting to host, ", netaddress
        return
    else
        put "Connected to ", netaddress
    end if

    GUI.Quit

end Join

process chat

    loop

        if resetcounter >= 6 then
            clearlines
            locate (1, 1)
            resetcounter := 0
        end if

        get strmessage : *

        resetcounter := resetcounter + 1

        if strmessage not= "" then

            strmessagetemp := strmessage

            put : stream (1), strname, ": ", strmessagetemp

            strmessagecloak := strname + ": " + strmessagetemp

            GUI.AddLine (inttextbox, strmessagecloak)

        end if
    end loop

end chat


process recieve

    loop

        for i : 1 .. 10

            get : stream (i), strmessagecloak : *

            if strmessagecloak not= "" then

                GUI.AddLine (inttextbox, strmessagecloak)

            end if


        end for
    end loop

end recieve

startframe := GUI.CreateLabelledFrame (10, 390, 293, 300, GUI.INDENT, "Chat")
joiny := GUI.CreateLabel (55, 370, "Welcome to the chat, Enter your name.")
ip1 := GUI.CreateTextFieldFull (105, 345, 100, "", DoNothing, GUI.INDENT, 0, 0)
ipsend := GUI.CreateButton (125, 310, 0, "Enter", name)
inttitle := GUI.CreateLabelFull (20, 280, "Messages", 250, 0, GUI.CENTER, 0)
inttextbox := GUI.CreateTextBoxFull (10, 10, 280, 265, GUI.INDENT, 0)

loop
    exit when GUI.ProcessEvent
end loop


GUI.Dispose (joiny)
GUI.Dispose (ipsend)
GUI.Dispose (ip1)

joiny2 := GUI.CreateLabel (55, 370, "Click the join button to join a chat.")
join2 := GUI.CreateButton (105, 330, 0, "Join Chat", Join)

cls
GUI.Refresh
GUI.ResetQuit
loop
    exit when GUI.ProcessEvent
end loop

cls
GUI.Refresh
GUI.ResetQuit

loop
    delay (2000)
    fork chat
    fork recieve
end loop

Author:  Miketron [ Fri Jan 12, 2007 11:46 am ]
Post subject:  Re: Networked Instant Messenger, Multi User Help.

Alright, I got it working. Had to find myself another version of turing just to use the .ResetQuit function Razz

Author:  Miketron [ Wed Jan 17, 2007 9:33 am ]
Post subject:  Re: Networked Instant Messenger, Multi User Help.

I am now having problems adding more users to the chat. In this process below it should be waiting until someone connects to the server before it continues, but it doesn't seem to be.

code:

process newclients

    loop

        for i : 3 .. 11

            if USERS < 10 then
           
                stream (i) := Net.WaitForConnection (port, netAddress (i))
                USERS := USERS + 1
               
            end if

        end for

    end loop

end newclients

Author:  Miketron [ Wed Jan 17, 2007 9:33 am ]
Post subject:  Re: Networked Instant Messenger, Multi User Help.

I am now having problems adding more users to the chat. In this process below it should be waiting until someone connects to the server before it continues, but it doesn't seem to be.

code:

process newclients

    loop

        for i : 3 .. 11

            if USERS < 10 then
           
                stream (i) := Net.WaitForConnection (port, netAddress (i))
                USERS := USERS + 1
               
            end if

        end for

    end loop

end newclients

Author:  rdrake [ Wed Jan 17, 2007 10:07 am ]
Post subject:  Re: Networked Instant Messenger, Multi User Help.

Why are you using the following code...?
code:
        for i : 3 .. 11
            % ...
        end for

Couldn't you just get rid of this, or is there a particular problem you use this to work around?

Also, constants (ie. USERS) do not normally change. Consider changing its casing (something along the line of users would do nicely).

Author:  Miketron [ Wed Jan 17, 2007 12:19 pm ]
Post subject:  Re: Networked Instant Messenger, Multi User Help.

code:
        for i : 3 .. 11
            % ...
        end for


it's to limit the amount of people in the chat, and it's needed to change the name of the different net addresses.

Author:  Miketron [ Thu Jan 18, 2007 9:18 am ]
Post subject:  Re: Networked Instant Messenger, Multi User Help.

For some reason the Adding New Clients process isn't working properly and it isn't waiting for the connection. After the first connection to I have to reset it back to waiting?

code:

var port : int := 3000

%--------Networking-----------
var netAddress : array 2 .. 11 of string
var stream : array 2 .. 11 of int

for i : 2 .. 11
    stream (i) := 0
end for

var intchoice : int
var strchoice : string (1)

%--------Message--------------
var strmessage : string
var strmessagetemp : string
var strmessagecloak : string

%--------Names----------------
var strname : string

%--------Server---------------
var USERS : int := 1

procedure host

    put "Chat started ", Net.LocalAddress
    put "Waiting for connection..."
    stream (2) := Net.WaitForConnection (port, netAddress (2))
    USERS := USERS + 1

end host

process newclients

    loop

        for i : 3 .. 11

            if USERS < 10 then
           
                stream (i) := Net.WaitForConnection (port, netAddress (i))
                USERS := USERS + 1
               
            end if

        end for

    end loop

end newclients


host

cls
fork newclients

loop

    for i : 2 .. 11

        if stream (i) > 0 then

            if Net.LineAvailable (stream (i)) then

                get : stream (i), strmessagecloak : *

                put strmessagecloak

                if strmessagecloak not= "" then

                    for j : 2 .. 11

                        if stream (j) > 0 then

                            if Net.LineAvailable (stream (j)) then

                                put : stream (j), strname, ": ", strmessagecloak

                            end if

                        end if

                    end for

                end if

            end if

        end if

    end for

end loop

Author:  Miketron [ Fri Jan 19, 2007 8:50 am ]
Post subject:  Re: Networked Instant Messenger, Multi User Help.

I was wondering if the port needs to change when you are connecting multiple users. I just found out that my messenger is not recieving the message it is sending, however the server IS reciving it.

code:

var port : int := 3000
var netAddress : array 1 .. 10 of string
var stream : array 1 .. 10 of int

for i : 1 .. 10
    stream (i) := 0
end for

var intchoice : int
var strchoice : string (1)
var strmessage : string
var strmessagetemp : string
var strmessagecloak : string
var strname : string
var USERS : int := 1

process newclients

    loop
        if USERS < 10 then
            put "Server"
            stream (USERS) := Net.WaitForConnection (port, netAddress (USERS))
            USERS := USERS + 1
            put "New User Connected"
        end if
    end loop

end newclients

fork newclients

loop
    for i : 1 .. 10
        if stream (i) > 0 then

            if Net.LineAvailable (stream (i)) then

                get : stream (i), strmessagecloak : *
                put strmessagecloak

                if strmessagecloak not= "" then
                    for j : 1 .. 10

                        if stream (j) > 0 then
                            if Net.LineAvailable (stream (j)) then
                                put : stream (j), strmessagecloak
                            end if
                            strmessagecloak := ""
                        end if

                    end for
                end if
            end if
        end if
    end for
end loop


If anyone could help me out with the possible error, or, give me some reccomendations for a different way of coding it. Here is the actual client code incase this is needed aswell.

code:

import GUI
setscreen ("graphics:300;400,nobuttonbar")
colourback (54)
cls

var port : int := 3000
var netaddress : string
var stream : array 1 .. 10 of int

for i : 1 .. 10
    stream (i) := 0
end for

var strmessage : string
var strmessagetemp : string
var strmessagecloak : string
var strname : string
var inttextbox : int
var inttitle : int
var startframe : int
var joiny : int
var join : int
var joiny2 : int
var join2 : int
var ip1 : int
var ip2 : int
var ipl : int
var ipsend : int
var resetcounter : int
resetcounter := 0

procedure clearlines
    locate (1, 1)
    put "" : 40
    locate (2, 1)
    put "" : 40
    locate (3, 1)
    put "" : 40
    locate (4, 1)
    put "" : 40
    locate (5, 1)
    put "" : 40
    locate (6, 1)
    put "" : 40
end clearlines

procedure DoNothing (text : string)
end DoNothing

procedure ipz
    netaddress := GUI.GetText (ip2)
    GUI.Quit
end ipz

procedure name
    strname := GUI.GetText (ip1)
    GUI.Quit
end name

procedure Join
    GUI.Dispose (joiny2)
    GUI.Dispose (join2)

    ip2 := GUI.CreateTextFieldFull (105, 345, 100, "", DoNothing, GUI.INDENT, 0, 0)
    ipsend := GUI.CreateButton (125, 310, 0, "Enter", ipz)
    joiny := GUI.CreateLabel (55, 370, "Please enter the ip below, and press enter.")
    cls
    GUI.Refresh
    GUI.ResetQuit

    loop
        exit when GUI.ProcessEvent
    end loop

    stream (1) := Net.OpenConnection (netaddress, port)

    if stream (1) < 0 then
        put "Failure connecting to host, ", netaddress
        return
    else
        put "Connected to ", netaddress
    end if

    GUI.Quit

end Join

process chat
    loop

        if resetcounter >= 6 then
            clearlines
            locate (1, 1)
            resetcounter := 0
        end if

        get strmessage : *
        resetcounter := resetcounter + 1

        if strmessage not= "" then

            strmessagetemp := strmessage
            put : stream (1), strname, ": ", strmessagetemp
            strmessagecloak := strname + ": " + strmessagetemp
            GUI.AddLine (inttextbox, strmessagecloak)

        end if
    end loop

end chat


process recieve

    loop
        if stream (1) < 0 then

            GUI.AddLine (inttextbox, "Server ip is incorrect")

        else

            get : stream (1), strmessagecloak : *
           
            if strmessagecloak not= "" then
                GUI.AddLine (inttextbox, strmessagecloak)
            end if
           
        end if
    end loop

end recieve

startframe := GUI.CreateLabelledFrame (10, 390, 293, 300, GUI.INDENT, "Chat")
joiny := GUI.CreateLabel (55, 370, "Welcome to the chat, Enter your name.")
ip1 := GUI.CreateTextFieldFull (105, 345, 100, "", DoNothing, GUI.INDENT, 0, 0)
ipsend := GUI.CreateButton (125, 310, 0, "Enter", name)

loop
    exit when GUI.ProcessEvent
end loop

GUI.Dispose (joiny)
GUI.Dispose (ipsend)
GUI.Dispose (ip1)

joiny2 := GUI.CreateLabel (55, 370, "Click the join button to join a chat.")
join2 := GUI.CreateButton (105, 330, 0, "Join Chat", Join)

cls
GUI.Refresh
GUI.ResetQuit

loop
    exit when GUI.ProcessEvent
end loop


cls
GUI.Refresh
GUI.ResetQuit

inttitle := GUI.CreateLabelFull (20, 280, "Messages", 250, 0, GUI.CENTER, 0)
inttextbox := GUI.CreateTextBoxFull (10, 10, 280, 265, GUI.INDENT, 0)

loop
    View.Update
    delay (10)
    fork chat
    fork recieve
end loop

Author:  Robert [ Sun Jan 21, 2007 11:37 am ]
Post subject:  Re: Networked Instant Messenger, Multi User Help.

I see it...

In the server:

code:

loop
    for i : 1 .. 10
        if stream (i) > 0 then

            if Net.LineAvailable (stream (i)) then

                get : stream (i), strmessagecloak : *
                put strmessagecloak

                if strmessagecloak not= "" then
                    for j : 1 .. 10

                        if stream (j) > 0 then
                            if Net.LineAvailable (stream (j)) then % This means only clients that have sent a message at the same time will recieve the other message. You don't want that.
                                put : stream (j), strmessagecloak
                            end if
                            strmessagecloak := "" % What exactly are you doing with this line in here? You'll want to move this outside of the for loop, I believe
                        end if

                    end for
                end if
            end if
        end if
    end for
end loop


Also, Turing sucks for multiple connections. You are forced to use multiple ports, so if you have the opportunity to switch to another language for the server, do it.

Author:  Miketron [ Sun Jan 21, 2007 1:17 pm ]
Post subject:  Re: Networked Instant Messenger, Multi User Help.

I was introduced to espresso recently, so I was up late and figured out how to correct my problem, but now I am left with the last two problems. My server is receiving the text but it is not sending it back out, or the receiving process isn't receiving it properly.

Server Code

code:


var port : int := 5535
var netaddress : array 1 .. 15 of string
var stream : array 1 .. 15 of int
var intchoice : int
var strchoice : string (1)
var strmessage : string
var strmessagetemp : string
var strmessagecloak : string
var strname : string
var users : int := 0


for i : 1 .. 15
    stream (i) := 0
end for

put "Server"
put Net.LocalAddress

stream (1) := Net.WaitForConnection (port, netaddress (1))

put "New User Connected"

users := users + 1

process newclients

    loop

        if users <= 15 then
            put "Waiting for Connection..."
            stream (users) := Net.WaitForConnection (port + users, netaddress (users))
            users := users + 1
            put "New User Connected"

        end if

    end loop

end newclients

fork newclients

loop

    delay (10)

    for i : 1 .. users

        if stream (i) > 0 then

            if Net.LineAvailable (stream (i)) then

                get : stream (i), strmessagecloak : *
                put strmessagecloak

                if strmessagecloak not= "" then

                    for j : 1 .. 15

                        if stream (j) > 0 then

                            if Net.LineAvailable (stream (j)) then

                                put : stream (j), strmessagecloak

                            end if

                        end if

                    end for

                end if
            end if
        end if
    end for

end loop

Client Code



import GUI
setscreen ("graphics:300;400,nobuttonbar")
colourback (54)
cls

%....Network....
var port : int := 5535
var netaddress : string
var stream : array 1 .. 10 of int
var counter : int := 0
var blnchat : boolean := false

for i : 1 .. 10
stream (i) := 0
end for
%....endNetwork....

%....Messages....
var strmessage, strmessagetemp, strmessagecloak, strmessagecheck, strname : string
var client : string
%....endMessages....

%....GUI.....
var inttextbox, intframe, intlabel, inttextfield, intbutton : int
%....endGUI....


%....ButtonProcedures....
procedure DoNothing (text : string)
end DoNothing

procedure ipz
netaddress := GUI.GetText (inttextfield)
GUI.Quit
end ipz

procedure message
strmessage := GUI.GetText (inttextfield)
GUI.Quit
end message

procedure name
strname := GUI.GetText (inttextfield)
GUI.Quit
end name

procedure Join
GUI.Quit
end Join
%....endButtonProcedures....


%....Forks....
process recieve

loop
if stream (1) < 0 then

GUI.AddLine (inttextbox, "Server ip is incorrect")

else

get : stream (1), strmessagecloak : *

if strmessagecloak not= "" then
if strmessagecloak not= strmessagecheck then
GUI.AddLine (inttextbox, strmessagecloak)
strmessagecheck := strmessagecloak
View.Update
end if
end if
end if
end loop

end recieve
%....endForks....

%....NameSet....
intframe := GUI.CreateLabelledFrame (10, 390, 293, 300, GUI.INDENT, "Client")
intlabel := GUI.CreateLabel (60, 370, "Welcome, Please enter a Username.")
inttextfield := GUI.CreateTextFieldFull (105, 345, 100, "", DoNothing, GUI.INDENT, 0, 0)
intbutton := GUI.CreateButton (125, 310, 0, "Enter", name)

loop
exit when GUI.ProcessEvent
end loop

GUI.Dispose (intlabel)
GUI.Dispose (intbutton)
GUI.Dispose (inttextfield)
cls
GUI.Refresh
GUI.ResetQuit
%....endNameSet....

%....JoinSet....
intlabel := GUI.CreateLabel (60, 360, "Click the join button to join a chat.")
intbutton := GUI.CreateButton (110, 320, 0, "Join Chat", Join)

loop
exit when GUI.ProcessEvent
end loop

GUI.Dispose (intlabel)
GUI.Dispose (intbutton)
cls
GUI.Refresh
GUI.ResetQuit
%....endJoinSet....

%....IpSet....
inttextfield := GUI.CreateTextFieldFull (105, 345, 100, "", DoNothing, GUI.INDENT, 0, 0)
intlabel := GUI.CreateLabel (55, 370, "Please enter the ip below, and press enter.")
intbutton := GUI.CreateButton (125, 310, 0, "Enter", ipz)

loop
exit when GUI.ProcessEvent
end loop

GUI.Dispose (intlabel)
GUI.Dispose (intbutton)
GUI.Dispose (inttextfield)
cls
GUI.Refresh
GUI.ResetQuit
%....endIpSet....

loop

stream (1) := Net.OpenConnection (netaddress, port + counter)

if stream (1) < 0 then
else
exit
end if

counter := counter + 1

if counter = 16 then
quit
end if

end loop

loop

View.Update
delay (10)
intlabel := GUI.CreateLabel (90, 360, "Enter your message below.")
inttextfield := GUI.CreateTextFieldFull (55, 335, 200, "", DoNothing, GUI.INDENT, 0, 0)
intbutton := GUI.CreateButton (130, 305, 0, "Send", message)
intlabel := GUI.CreateLabelFull (20, 280, "Messages", 250, 0, GUI.CENTER, 0)
inttextbox := GUI.CreateTextBoxFull (10, 10, 280, 265, GUI.INDENT, 0)

if blnchat = false then
fork recieve
end if

loop
exit when GUI.ProcessEvent
end loop

strmessagetemp := strmessage
strmessagecloak := strname + ": " + strmessagetemp
put : stream (1), strmessagecloak

cls
GUI.Refresh
GUI.ResetQuit

blnchat := true

end loop


code:





Author:  Robert [ Sun Jan 21, 2007 1:24 pm ]
Post subject:  RE:Networked Instant Messenger, Multi User Help.

Look up. I gave you the answer in my last post.

Author:  Miketron [ Sun Jan 21, 2007 1:31 pm ]
Post subject:  Re: Networked Instant Messenger, Multi User Help.

My bad. However, I just check and the server is sending the messages fine. The problem is in the client, it is not receiving.

Edit: I just checked the turing documentation, and I now see what you mean. Thank you!

Author:  Robert [ Sun Jan 21, 2007 1:44 pm ]
Post subject:  RE:Networked Instant Messenger, Multi User Help.

No problem. Good luck with your program!


: