Built on TCP/IP
Internet Pack includes components for standard protocols such as HTTP, FTP, SMTP, and POP3. Its reusable connection classes also let you implement your own TCP/IP protocols.
The library is available for all Elements target platforms and can be used alongside Elements RTL in cross-platform projects.
Serve a File over HTTP
Create an Elements console project for any target and add a reference to RemObjects.InternetPack. Put an index.html file inside a www folder in the program’s working directory.
namespace HttpServerExample;
uses
RemObjects.InternetPack.Http;
type
Program = class
public
class method Main;
begin
var lServer := new SimpleHttpServer;
lServer.RootPath := "www";
lServer.Port := 8080;
lServer.Open;
readLn;
lServer.Close;
end;
end;
end.
version 1;
use RemObjects.InternetPack.Http;
type Program: class {
static method Main(): Int32! {
using _server = new SimpleHttpServer() {
_server.RootPath = "www";
_server.Port = 8080;
_server.Open();
readLn();
}
return 0;
}
}
using RemObjects.InternetPack.Http;
static class Program
{
static void Main()
{
var server = new SimpleHttpServer();
server.RootPath = "www";
server.Port = 8080;
server.Open();
readLn();
server.Close();
}
}
from RemObjects.InternetPack.Http import SimpleHttpServer
server = SimpleHttpServer()
server.RootPath = "www"
server.Port = 8080
server.Open()
readLn()
server.Close()
import RemObjects.InternetPack.Http.*;
class Program {
public static void main(String[] args) {
SimpleHttpServer server = new SimpleHttpServer();
server.RootPath = "www";
server.Port = 8080;
server.Open();
readLn();
server.Close();
}
}
package main
import "RemObjects.InternetPack.Http"
func main() {
server := RemObjects.InternetPack.Http.SimpleHttpServer{}
server.RootPath = "www"
server.Port = 8080
server.Open()
readLn()
server.Close()
}
import RemObjects.InternetPack.Http
public class Program {
public static func Main() {
let server = SimpleHttpServer()
server.RootPath = "www"
server.Port = 8080
server.Open()
_ = readLn()
server.Close()
}
}
Imports RemObjects.InternetPack.Http
Module Program
Sub Main()
Dim server As New SimpleHttpServer()
server.RootPath = "www"
server.Port = 8080
server.Open()
readLn()
server.Close()
End Sub
End Module
Fetch the File from a Client
With the server running, use this snippet inside another console project with the same references and the RemObjects.InternetPack.Http namespace in scope.
var lClient := new HttpClient;
writeLn(lClient.Get("http://127.0.0.1:8080/index.html"));
using _client = new HttpClient() {
writeLn(_client.Get("http://127.0.0.1:8080/index.html"));
}
var client = new HttpClient();
writeLn(client.Get("http://127.0.0.1:8080/index.html"));
client = HttpClient()
writeLn(client.Get("http://127.0.0.1:8080/index.html"))
HttpClient client = new HttpClient();
writeLn(client.Get("http://127.0.0.1:8080/index.html"));
client := RemObjects.InternetPack.Http.HttpClient{}
writeLn(client.Get("http://127.0.0.1:8080/index.html"))
let client = HttpClient()
writeLn(client.Get("http://127.0.0.1:8080/index.html"))
Dim client As New HttpClient()
writeLn(client.Get("http://127.0.0.1:8080/index.html"))
The Engine Behind ESP (and This Website)
Internet Pack supplies the networking layer for the built-in web server used by Elements Server Pages. You can also use it directly for your own clients and servers.