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.
Just a few other nitpicks:
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
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.
|
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:
(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:
|
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 |
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.
|
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.
|
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...?
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. | ||
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?
|
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.
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.
|
Author: | Robert [ Sun Jan 21, 2007 11:37 am ] | ||
Post subject: | Re: Networked Instant Messenger, Multi User Help. | ||
I see it... In the server:
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
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
|
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! |