mactjaap
Well-known member
I would like to make a ultra light version of a web server for Macintosh. I really would like that it runs on System 6.
It has to serve only one page or one small string of html. Just for the fun of running a web server on an old Mac.
This is how I started.
I have found an old peace of code called TCPExample. It is written in Pascal. The actuel code starts a connection to port 79 of the finger daemon and gives you information from the finger server about a user. Like this:
My first goal was to get the code do something else, like a telnet connection to port 23 and login. I added a passwd variable and sending it to the server.
But no success. I guess, I’m missing the point.. I do get a connection, because I get:
Connection Established
This is the part if a connection is a succes.
I also see something happening with a tcpdump
My question is.. Could someone help me a little bit getting this code run. I’m not much of a programmer, but willing to learn!
This is the link on Internet: http://www.macgui.com/usenet/?group=17&id=8393
Turbo Pascal: http://macintoshgarden.org/apps/turbo-pascal-10
Send me a PM if you need more. I use Turbo Pascal 4.5
This is the code I have.
It has to serve only one page or one small string of html. Just for the fun of running a web server on an old Mac.
This is how I started.
I have found an old peace of code called TCPExample. It is written in Pascal. The actuel code starts a connection to port 79 of the finger daemon and gives you information from the finger server about a user. Like this:
Code:
Login: macipgw Name: MacIPgw
Directory: /home/macipgw Shell: /bin/sh
Last login Wed Oct 16 21:56 (UTC) on pts/1 from 192.168.62.201
No Mail.
No Plan.
Code:
passwd = 'test123';
s := concat(user_name, cr, lf); { Send the line that telnet wants, complete with crlf }
p := concat(passwd, cr, lf); { Send the line that telnet wants, complete with crlf }
Connection Established
This is the part if a connection is a succes.
Code:
C_Established: begin { Happens once per succesful connection establishment }
writeln('Connection Established');
Code:
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on em0, link-type EN10MB (Ethernet), capture size 96 bytes
23:36:17.470695 IP 192.168.62.9.dls-monitor > 192.168.62.10.telnet: Flags [s], seq 2856448, win 16616, options [mss 1460,wscale 0,eol], length 0
23:36:17.470750 IP 192.168.62.10.telnet > 192.168.62.9.dls-monitor: Flags [s.], seq 3540554349, ack 2856449, win 65535, options [mss 1460,nop,wscale 3], length 0
23:36:17.575401 IP 192.168.62.9.dls-monitor > 192.168.62.10.telnet: Flags [.], ack 1, win 17520, length 0
23:36:17.638188 IP 192.168.62.10.telnet > 192.168.62.9.dls-monitor: Flags [P.], ack 1, win 8212, length 3
23:36:17.698518 IP 192.168.62.9.dls-monitor > 192.168.62.10.telnet: Flags [.], ack 4, win 17520, length 0
This is the link on Internet: http://www.macgui.com/usenet/?group=17&id=8393
Turbo Pascal: http://macintoshgarden.org/apps/turbo-pascal-10
Send me a PM if you need more. I use Turbo Pascal 4.5
This is the code I have.
Code:
program KenExampleCode;
{ You can do anything you want with this code - if you can make any money out of it, you'll be doing well! }
uses
TCPTypes, TCPStuff, TCPConnections;
const
user_name = 'mactjaap';
dest_name = '192.168.62.10';
dest_port = 23;
passwd = 'test123';
nul = chr(0);
lf = chr(10);
cr = chr(13);
var
oe: OSErr;
cp: connectionIndex;
quitNow: boolean;
cer: connectionEventRecord; { Event record for TCP events, simmilar to EventRecord }
s: str255;
p: str255;
count: longInt;
gotlinefeed: boolean;
begin
ShowText;
quitNow := false;
oe := InitConnections; { Startup the TCP units }
if oe = noErr then begin
oe := FindAddress(cp, dest_name, nil);
if oe = noErr then begin
count := 0;
while not quitNow do begin
if GetConnectionEvent(any_connection, cer) then begin { Get the next TCP event }
case cer.event of
C_Found: begin
writeln('Found ', dest_name, ' has address ', pointer(cer.value));
oe := NewActiveConnection(cp, Default_TCPBUFFERSIZE, cer.value, dest_port, nil);
{ Open an active connection to the Finger port on dest_name }
end;
C_SearchFailed: begin
writeln('Couldn''t fine the address for ', dest_name);
quitNow := true;
end;
C_Established: begin { Happens once per succesful connection establishment }
writeln('Connection Established');
s := concat(user_name, cr, lf); { Send the line that telnet wants, complete with crlf }
p := concat(passwd, cr, lf); { Send the line that telnet wants, complete with crlf }
if oe <> noErr then
CloseConnection(cp); { Better close the connection if we can't send anything to it! }
end;
C_FailedToOpen:
writeln('Ooops, connection failed to open... Error is ', cer.value, ' Timed out is ', cer.timedout);
{ Example, network unreachable etc. Error code is in cer.value }
C_Closing: begin
writeln('Connection closing');{ Gets called when the connection starts closing down}
CloseConnection(cer.connection); { Close our side of the connection }
end;
C_Closed: begin
writeln('Connection closed, quit now');
quitNow := true; { The connection is closed, quit the program }
end;
C_CharsAvailable: begin
{$PUSH}
{$R-}
oe := TCPReceiveUpTo(cer.tcpc, 10, 60, @s[1], 255, count, gotlinefeed);
{ Recieve characters up to a line feed }
if (count > 0) & (s[count] = lf) then { strip off linefeed }
count := count - 1;
if (count > 0) & (s[count] = cr) then { strip off cr }
count := count - 1;
s[0] := chr(count);
{$POP}
if gotlinefeed then begin { if we got a linefeed, print the string, otherwise go round again and wait for more characters }
writeln(s);
count := 0;
end;
end;
end;
end;
end;
end;
FinishEverything; { Close everything, clean up }
{ ALWAY CALL THIS, OR YOU WILL BE SORRY! }
end;
writeln('Click to quit');
while not Button do
;
end.