Net. Functions
Author |
Message |
Sean
|
Posted: Wed Mar 19, 2008 3:02 pm Post subject: Net. Functions |
|
|
With the Net functions built into Turing, there is a Chat program available.
Regarding the program, I was wondering if it is possible to have more then two users talking at once, and have a large group instead?
I have chatted before with another person, running my client in a .t format, while having the server in an .exe format. If possible, how would I be able to open it up for more then two people?
Or is it scripted already to allow them to join? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Dan
|
Posted: Wed Mar 19, 2008 6:15 pm Post subject: RE:Net. Functions |
|
|
I am not sure witch example or chat program you are talking about, however it is deftaly posible to have mulity user chat in turing.
You need to have a server that gets messages from the clients and then relays it to each client (other then the one that sent it). The server also has to wait for new connections witch means you might need to use processes to deal with the blocking functions. |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
Sean
|
Posted: Wed Mar 19, 2008 6:23 pm Post subject: Re: Net. Functions |
|
|
Turing: |
% The "Chat" program
const chatPort : int := 5055
var choice : int
loop
put "Enter 1 to run chat server"
put "Enter 2 to run chat session"
put "Choice: " ..
get choice
exit when choice = 1 or choice = 2
end loop
var netStream : int
var netAddress : string
if choice = 1 then
netStream := Net.WaitForConnection (chatPort, netAddress )
else
put "Enter the address to connect to: " ..
get netAddress
netStream := Net.OpenConnection (netAddress, chatPort )
if netStream <= 0 then
put "Unable to connect to ", netAddress
return
end if
end if
Draw.Cls
put "Connected to ", netAddress
var localRow : int := 2
var localCol : int := 1
var remoteRow := maxrow div 2
var remoteCol : int := 1
var ch : char
View.Set ("noecho")
loop
if hasch then
ch := getchar
put : netStream, ch
if ch = '\n' then
localRow := localRow mod (maxrow div 2) + 1
localCol := 1
Text.Locate (localRow, localCol )
put "" % Clear to end of line
Text.Locate (localRow, localCol )
else
Text.Locate (localRow, localCol )
put ch ..
localCol + = 1
end if
end if
if Net.CharAvailable (netStream ) then
get : netStream, ch
if ch = '\n' then
remoteRow := remoteRow mod (maxrow div 2) +
1 + (maxrow div 2)
remoteCol := 1
Text.Locate (remoteRow, remoteCol ) put "" % Clear to end of line
Text.Locate (remoteRow, remoteCol )
else
Text.Locate (remoteRow, remoteCol )
put ch ..
remoteCol + = 1
end if
end if
end loop
|
Using the example from Turing for my testing right now, I can connect with two people so far, but I believe that a firewall prevented my connection with another. |
|
|
|
|
|
Sean
|
Posted: Wed Mar 19, 2008 7:49 pm Post subject: Re: Net. Functions |
|
|
Running it on the same computer, I encountered a problem.
Once setting it up as a server, in an exe format. I then proceeded to load the .t format, and join as a client, but to my luck, the server was already a client.
Does this mean, I need not be a client to commence communications with others? And why does it display it like this:
Quote:
S
E
A
N
?
I find that rather annoying, having to read up and down, I bet there is a way for me to format it, but I have no idea where to format it from the code mentioned above. |
|
|
|
|
|
agnivohneb
|
Posted: Thu Mar 20, 2008 8:55 am Post subject: RE:Net. Functions |
|
|
I have been working on this for some time now. I have decided to take the route dan mentioned but have not had the time to do it. I have made preveus versions all available at
http://turingnetchatserver.doesntexist.com/ |
|
|
|
|
|
Sean
|
Posted: Thu Mar 20, 2008 3:10 pm Post subject: Re: Net. Functions |
|
|
Thanks for the link, I've downloaded your version.
Now, I'm just waiting on someone to connect with. Other then that, it seems to be scripted well, and should do what I wanted. |
|
|
|
|
|
agnivohneb
|
Posted: Thu Mar 20, 2008 3:53 pm Post subject: RE:Net. Functions |
|
|
mmmk I'm glad you like it. Like I said I am trying to create a server version but have no time. I might get a chance this weekend. |
|
|
|
|
|
Sean
|
Posted: Thu Mar 20, 2008 4:14 pm Post subject: RE:Net. Functions |
|
|
Supposibly Mackie has developed the Grass/Character thing for the chat, like we planned in class one day.
We've got to test that out too. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
agnivohneb
|
Posted: Mon Mar 24, 2008 3:07 pm Post subject: RE:Net. Functions |
|
|
I have done it. I did have time this weekend to finish the server. have a look, I posted it on the server.
http://turingnetchatserver.doesntexist.com/ |
|
|
|
|
|
blackhacker
|
Posted: Mon Aug 18, 2008 10:25 am Post subject: RE:Net. Functions |
|
|
var hostAddr : string := "128.100.5.1"
put "The machine name of ", hostAddr, " is ",
Net.HostNameFromAddress (hostAddr) |
|
|
|
|
|
DemonWasp
|
Posted: Mon Aug 18, 2008 11:01 am Post subject: RE:Net. Functions |
|
|
One of the problems you may encounter in Turing is that once a connection has been formed on a given port, you can no longer listen on that port, as it is "in use". Therefore, if you have a standard port that your client expects to connect to the server on, you have to do some magic.
Naive Way (maximum one client, one server):
1. Server listens on port X.
2. Client connects to Server on port X.
3. Server cannot listen on port X again
Better Way (no real maximum that you'll run into):
1. Server listens on port X.
2. Client connects to Server on port X.
3. Server says "Y" to Client; Client disconnects from Server and reconnects on port Y (chosen so that the server never selects two Y's the same at the same time).
4. Server listens on port X again, so that more clients can connect on that port.
It's not flawless, but it does let you have multiple connections to a "server" in Turing. |
|
|
|
|
|
|
|