
-----------------------------------
Mash
Mon Jan 26, 2009 5:23 pm

.NET Commands Help
-----------------------------------
Hi.  I've created a working chat server/client thing which works fine for me locally on my computer (but using my external ip.)  However I gave my friend the client and it gives him an error on "get : netStream, port" on line 32 of the below code. 

The idea of these 2 servers and 1 client is that the client first connects to the logon server which tells them how many users are connected to the server and therefore which port to connect on, and then the user is able to connect to the server on that port.  (Much faster than using turing to check each port for connectivity.)  When I run the servers on my own computer it works fine, even for multiple chat clients.

Heres the client code:

var netStream : int
var test, test2, oldtest : string
var port : int

oldtest := ""
test2 := ""

process checkforinput
    loop
	if Net.LineAvailable (netStream) then
	    get : netStream, test2 : *
	end if
	if oldtest not= test2 then
	    put test2
	    oldtest := test2
	end if
    end loop
end checkforinput

process getTest
    loop
	get test : *
	put : netStream, test
	exit when test = "disc"
    end loop
end getTest

put "Connecting to login server.. "
netStream := Net.OpenConnection ("99.243.78.26", 5500)
if netStream > 0 then
    get : netStream, port

    Net.CloseConnection (netStream)

    put "Connecting to world server on port ", port, "..."
    netStream := Net.OpenConnection ("99.243.78.26", port)

    if netStream > 0 then
	put "Connected."
	fork checkforinput
	fork getTest
    else
	put "Cannot connect to server."
    end if
else
    put "Cannot connect to login server.. "
end if


Heres the main server:

const port := 5535
const MAXUSERS := 20

var netStream : array 0 .. 1000 of int
var ip : string
var test : string := ""
var connections : int := 0

for i : 1 .. 1000
    netStream (i) := 0
end for

process awaitConnection
    loop
	if connections  0 then
	    if Net.LineAvailable (netStream (i)) then
		get : netStream (i), test : *
		exit
	    end if
	    if test = "disc" then
		test := ""
		%connections -= 1
	    else
		locate (2, 1)
		put : netStream (i), test
	    end if
	end if
    end for
end loop


Heres the "logon" server:


% this will simply tell all connected users the number of
% connected users on the other server.

var netStream : int := 0
var serverStream : int
var test : int := 0
var port : int := 5500
var ip : string

put "Connecting"
serverStream := Net.OpenConnection ("127.0.0.1", port + 1)

process talktoserver
    loop
	if serverStream > 0 then
	    if Net.LineAvailable (serverStream) then
		get : serverStream, test
	    end if
	end if
    end loop
end talktoserver

fork talktoserver

process getConnected
    loop
	if netStream >= 0 then
	    locate (3, 1)
	    put "Waiting for connection"
	    netStream := Net.WaitForConnection (port, ip)
	end if
    end loop
end getConnected

fork getConnected

loop
    if serverStream > 0 then
	locate (1, 1)
	put "Connected"
	locate (2, 1)
	put test
	if netStream > 0 then
	    put : netStream, test + 5535
	    Net.CloseConnection (netStream)
	    netStream := 0
	end if
    end if
end loop


Anyone know the issue?


Thanks.

-----------------------------------
andrew.
Mon Jan 26, 2009 6:06 pm

RE:.NET Commands Help
-----------------------------------
I'm no expert on Turing net commands, so I can't really pinpoint your problem. However, it may lie in the use of processes. Try not to use processes if it is possible. Put each thing in a procedure. Again, I am not good at net commands in Turing so I don't know if processes are required.

-----------------------------------
saltpro15
Mon Jan 26, 2009 6:50 pm

RE:.NET Commands Help
-----------------------------------
After looking at your code I agree with andrew. There shouldn't be any other problem as far as I can tell

-----------------------------------
Mash
Mon Jan 26, 2009 8:11 pm

Re: .NET Commands Help
-----------------------------------
In Turings .NET commands without processes I cannot do the same things as with processes.  Using a loop turing stops all processing until a user has connected with netStream (connections + 1) := Net.WaitForConnection (port + connections, ip).  And it also stops everything for a get command.   Using a process was the only way around I could find.  Theres no way to check if a user is looking for a connection and only if a user is looking then connect him, you must sit at the Net.WaitForConnection function until a user connects and so I must be doing other things during this period of time with other connected users.  Also, because the get command stops everything, I cannot, with the client, continually check for sent messages from other users until the user actually typed a message and pressed enter...so again a process I must use.

I have not found any alternatives.  If you guys know of any, tell me and I can try it without processes.  To me, it doesnt seem like processes would be the issue since the error that occurs is on a line before any process is forked.

Thanks.

-----------------------------------
saltpro15
Mon Jan 26, 2009 9:04 pm

RE:.NET Commands Help
-----------------------------------
check Turing 4.1.1 netchat program, the code is similar to this, maybe comparing them will help you find your problem

-----------------------------------
ProxyKaliber
Thu May 25, 2017 10:39 am

Re: .NET Commands Help
-----------------------------------
Hello, I know this topic is old but I'm replying to just let you guys know that I'll be working on updating this code to the current version of turing as I'm getting more errors as described by the original poster. I'm in ICS4C and its a 4 way split between ICS3C, ICS3U, ICS4C, and ICS4U class and we are given more self exploration since the teacher has to focus his time a lot more on the grade 11 which is fine by me because I get to focus on my interests and I am actually motivated to try and work on this code. Let me know if there's anything I should know while I work on this. I'm new to net command and I refer a lot to this site as well as the turing keyword reference. 

Cheers,

Kaliber

P.S. BB Code Signature will be coming soon

-----------------------------------
ProxyKaliber
Mon May 29, 2017 9:52 am

Re: .NET Commands Help
-----------------------------------
Nevermind, I was mistake. It's all in seperate turing files. My bad. Apopologies.
