%set the screen setings and graphics
setscreen ("Graphics:vga")
setscreen ("Graphics:500;400")
%vars and consts
const port1 : int := 5555 %port to be used
var sorc : string (1)
var data : int
var ip1 : string
var name1 : string
var help : string (1)
var address1 : string
var rowhere : int := 2
var colhere : int := 1
var rowthere : int := maxrow div 2
var colthere : int := 1
var ch : char
var yourip : string
var yourname : string
var madeby:string:="Dan"
cls
%disalp loacl adress
yourip := Net.LocalAddress %get ip
yourname := Net.LocalName %get name
put "Your IP is: ", yourip, " ", "Your Name is: ", yourname
put ""
%loop to see if conputer is host or not
loop
%disply choies and input respones
put "1. Host Chat"
put "2. Join Chat"
put "3. Help"
put "4. Exit"
put ""
getch (sorc)
%creal screen and keep loacl mahine info
cls
put "Your IP is: ", yourip, " ", "Your Name is: ", yourname
put ""
%see if exit
if sorc = "4" then
cls
put "Good Bye"
return %end program
%if help
elsif sorc = "3" then
loop
%creal screen and keep loacl mahine info
cls
put "Your IP is: ", yourip, " ", "Your Name is: ",
yourname
put ""
%put up help choies and get input
put "1. Convernt IP to Host Name"
put "2. Convernt Host Name to IP"
put "3. Exit Help"
getch (help)
% if user picks 1
if help = "1" then
%creal screen and keep loacl mahine info
cls
put "Your IP is: ", yourip, " ",
"Your Name is: ", yourname
put ""
%aks user for ip number and get data
put "Put in the IP number to convert (EX. 128.100.5.1)"
put
"Note: you need to be onilen or on the nerwrok for this to wrok"
get ip1
%out put data
put ""
put "Host Name is: ", Net.HostNameFromAddress (ip1)
delay (3000)
%if user picks 2
elsif help = "2" then
%clera screen and keep loacl mahine info
cls
put "Your IP is: ", yourip, " ",
"Your Name is: ", yourname
put ""
%ask user for host name
put "Put in the Host Name to convert (EX.
www.yahoo.com)"
put
"Note: you need to be onilen or on the nerwrok for this to wrok"
get name1
%output data
put ""
put "IP Number is: ", Net.HostAddressFromName (name1)
delay (3000)
end if
%exit when user picks 3
exit when help = "3"
end loop
%creal screen and keep loacl mahine info
cls
put "Your IP is: ", yourip, " ",
"Your Name is: ", yourname
put ""
%resata the meun
put "1. Host Chat"
put "2. Join Chat"
put "3. Help"
put "4. Exit"
put ""
end if
%exit when user picks 1 or 2
exit when sorc = "1" or sorc = "2"
end loop
%see if user is host and wait for clint to conect
if sorc = "1" then
data := Net.WaitForConnection (port1, address1)
%wait for clint to conect on port 5555
%see if user is clint and conect to host
else
%ask user where to conect to
put "Enter IP or name of conputer to concet to."
get address1
%open contection to host
data := Net.OpenConnection (address1, port1)
%open contection to host on port 5555
if data <= 0 then %see if connection was sucesfull
put "ERROR:01:Unsble to connect to ", address1
%if it was not then put error mesag
return %end progame
end if
end if
%clera screen and keep loacl mahine info
cls
put "Your IP is: ", yourip, " ", "Your Name is: ", yourname
put ""
put "Connected to ", address1
%trun off echo
setscreen ("noecho")
%loop to send data
loop
if hasch then
%get data from key borad and send it
ch := getchar
put : data, ch ..
%if enter is hit then move down line
if ch = "\n" then %see if enter is hit
rowhere := rowhere mod (maxrow div 2) + 1 %chage line
rowthere := 1 %chage line
colhere := 1
Text.Locate (rowhere, colhere)
put "" %clrea line
%Text.Locate (rowhere, colhere)
%if it is not an enter and just text
else
color (brightblue)
if colhere < maxx - 10 then
Text.Locate (rowhere, colhere)
put ch .. %put the text you are typeing
colhere += 1
elsif colhere > maxx - 10 then
rowhere := rowhere mod (maxrow div 2) + 1 %chage line
rowthere := 1 %chage line
colhere := 1
Text.Locate (rowhere, colhere)
put "" %clrea line
end if
end if
end if
%geting data from other conputer
if Net.CharAvailable (data) then %see if there is any thing to get
get : data, ch %get text form other conputer
%if enter then move down line
if ch = "\n" then %see if it is an enter
rowthere := rowthere mod (maxrow div 2) + 1 + (maxrow div 2)
colthere := 1
Text.Locate (rowthere, colthere)
put "" %ceare line
%if not enter and just text
else
color (brightred)
if colhere < maxx - 10 then
Text.Locate (rowthere, colthere)
put ch .. %put text form other conputer
colthere += 1
elsif colhere > maxx - 10 then
rowthere := rowthere mod (maxrow div 2) + 1 + (maxrow div 2)
colthere := 1
Text.Locate (rowthere, colthere)
put "" %ceare line
end if
end if
end if
end loop