
-----------------------------------
Skizzarz
Thu Nov 13, 2003 5:28 pm

Improving your chat prog
-----------------------------------
2 days ago i tried ur chat prog on the school comps... and i thought it was cool, im a nub but i improved it a little bit, but im wandering, how could i make a third option called "connect" that would send a message to all the ip's in the prog ( i have 4 ip's in the prog that i will explain tomorrow when i send u the full prog from school ) and tell the users that i am online , also how could i send them a message without us connecting? heres a sample of wut i started 2nite, one more thing, i want to put 'username' "says: " in front of the message i send, is that part of the code in the right spot? thx allot, here it is

setscreen ("graphics:300;400")
var stream : int := 0 % Used for sending data 
var msgBack : string % The message that gets sent back and forth 
var address : string % IP address for each computer 
var message : string  % Message that you send 
var status : int % Status host/client 
var name : string
const PORT := 5555 % Port to connect through 


put "What would you like to do?" 
put "1:Host" 
put "2:Join" 
put "3:Connect"
get status 

if status = 1 then 
    stream := Net.WaitForConnection (PORT, address) % Wait for a user to connect 
elsif status = 2 then 
    put "What is the IP of the computer you want to connect to?" 
    get address 
    stream := Net.OpenConnection (address, PORT) % Connect to the IP inputted 
end if
% elsif status = 3 then
% i dont now wut to put for choice 3
 
cls 
put "Connected to ", address 

loop 
    if hasch then % If key pressed 
        get message : *  % store all input in var message when enter is pressed 
        put : stream, name, " says: ", message  % Send the message over the stream 
    end if 
    if Net.LineAvailable (stream) then % If a line of text has been sent 
        get : stream, msgBack : * % grab the line of text 
        put msgBack % print it to the screen 
    end if 
end loop 


(my version at school has much more to it and i will post it in this "room" or wutever u call it, tomorow)

-----------------------------------
Tony
Thu Nov 13, 2003 6:29 pm


-----------------------------------
the way net messaging is suppost to be set up, is that the host computer is constantly scanning its ports for incomming connections (fork process).

Once a new connection is established, you can have host send out messages such as "user is now online"

As for the user says: part - its in the right place. Although if its not working, you might try using + operator instead of ,

-----------------------------------
Skizzarz
Fri Nov 14, 2003 1:32 pm


-----------------------------------
here is the better version:

setscreen ("graphics:300;400")
var stream : int := 0 % Used for sending data 
var msgBack : string % The message that gets sent back and forth 
var address : string % IP address for each computer 
var message : string  % Message that you send 
var status : int % Status host/client 
var name : string 
const PORT := 5555 % Port to connect through 

put "        S k i z z c h a t  V.2" 
put "What is your nick?" 
get name 
put "What would you like to do?" 
put "1:Host" 
put "2:Join" 
get status 

if status = 1 then 
  stream := Net.WaitForConnection (PORT, address) % Wait for a user to connect 
else 
  put "What is the IP of the computer you want to connect to?" 
  get address 
  if address = "alex" then 
  address := "172.22.41.44" 
  elsif address = "paul" then 
  address := "172.22.40.123" 
  elsif address = "patrick" then 
  address := "172.22.41.58" 
  elsif address = "chris" then 
  address := "172.22.40.141" 
  end if 
  stream := Net.OpenConnection (address, PORT) % Connect to the IP inputted 
end if 
cls 
if address = "172.22.41.44" then 
address := "Alex" 
elsif address = "172.22.40.123" then 
address := "Paul" 
elsif address = "172.22.40.141" then 
address := "Chris" 
elsif address = "172.22.41.58" then 
address := "Patrick" 
end if 
put "Connected to ", address 

loop 

  if hasch then % If key pressed  
      get message : *  % store all input in var message when enter is pressed 
      put : stream, name, " says: ", message  % Send the message over the stream 
  end if 
  if Net.LineAvailable (stream) then % If a line of text has been sent 

      color (12) 
      get : stream, msgBack : * % grab the line of text 
      put msgBack % print it to the screen 
  end if 
end loop

-----------------------------------
Skizzarz
Fri Nov 14, 2003 1:40 pm


-----------------------------------
super ultra revised version... lol (thx for the help)

setscreen ("graphics:300;400")
var stream : int := 0 % Used for sending data 
var msgBack : string % The message that gets sent back and forth 
var address : string % IP address for each computer 
var message : string  % Message that you send 
var status : int % Status host/client 
var name : string 
const PORT := 5555 % Port to connect through 

put "        S k i z z c h a t  V.2" 
put "What is your nick?" 
get name 
put "What would you like to do?" 
put "1:Host" 
put "2:Join" 
get status 

if status = 1 then 
  stream := Net.WaitForConnection (PORT, address) % Wait for a user to connect 
else 
  put "What is the IP of the computer you want to connect to?" 
  get address 
  if address = "alex" then 
  address := "172.22.41.44" 
  elsif address = "paul" then 
  address := "172.22.40.123" 
  elsif address = "patrick" then 
  address := "172.22.41.58" 
  elsif address = "chris" then 
  address := "172.22.40.141" 
  end if 
  stream := Net.OpenConnection (address, PORT) % Connect to the IP inputted 
end if 
cls 
if address = "172.22.41.44" then 
address := "Alex" 
elsif address = "172.22.40.123" then 
address := "Paul" 
elsif address = "172.22.40.141" then 
address := "Chris" 
elsif address = "172.22.41.58" then 
address := "Patrick" 
end if 
put "Connected to ", address 

loop 

  if hasch then % If key pressed  
      color (16)
      put name, " says: "..
      get message : *  % store all input in var message when enter is pressed 
      put : stream, name, " says: ", message  % Send the message over the stream 
  end if 
  if Net.LineAvailable (stream) then % If a line of text has been sent 

      color (12) 
      get : stream, msgBack : * % grab the line of text 
      put msgBack % print it to the screen 
  end if 
end loop

-----------------------------------
Skizzarz
Fri Nov 14, 2003 1:54 pm


-----------------------------------
sorry to keep doin this but this is the final version of today...=)

setscreen ("graphics:300;400")
var stream : int := 0 % Used for sending data 
var msgBack : string % The message that gets sent back and forth 
var address : string % IP address for each computer 
var message : string  % Message that you send 
var status : int % Status host/client 
var name : string 
const PORT := 5555 % Port to connect through 

put "        S k i z z c h a t  V.2" 
put "What is your nick?" 
get name 
put "What would you like to do?" 
put "1:Host" 
put "2:Join" 
get status 

if status = 1 then 
  stream := Net.WaitForConnection (PORT, address) % Wait for a user to connect 
else 
  put "What is the IP of the computer you want to connect to?" 
  get address 
  if address = "alex" then 
  address := "172.22.41.44" 
  elsif address = "paul" then 
  address := "172.22.40.123" 
  elsif address = "patrick" then 
  address := "172.22.41.58" 
  elsif address = "chris" then 
  address := "172.22.40.141" 
  end if 
  stream := Net.OpenConnection (address, PORT) % Connect to the IP inputted 
end if 
cls 
if address = "172.22.41.44" then 
address := "Alex" 
elsif address = "172.22.40.123" then 
address := "Paul" 
elsif address = "172.22.40.141" then 
address := "Chris" 
elsif address = "172.22.41.58" then 
address := "Patrick" 
end if 
put "Connected to ", address 

loop 
color (16)
  
  if hasch then % If key pressed  
      color (16)
      get message : *  % store all input in var message when enter is pressed 
      put : stream, name, " says: ", message  % Send the message over the stream 
  end if 
  if Net.LineAvailable (stream) then % If a line of text has been sent 

      color (12) 
      get : stream, msgBack : * % grab the line of text 
      put msgBack % print it to the screen 
  end if 
end loop
