Skip to main content
deleted 43 characters in body
Source Link
Kuba
  • 137.7k
  • 13
  • 289
  • 751

Very often SVG makes sense, it will scale well with magnification. This idea does not deserve a separate answer so additionally I rewrote the code in a more idiomatic style:

server = SocketListen[8000
, Function[{assoc}
  , Module[
      { client = assoc["SourceSocket"], inputString, response}

    , inputString = ImportString[assoc["Data"], "HTTPRequest"] @ "Query" // Lookup["expr"]

    ; response = HTTPResponse[
       GenerateHTTPResponse ExportString[ToExpression[inputString],@ "SVG"]ExportForm[
      , <|"ContentType" ->ToExpression[inputString], "image/svg+xml"|>"SVG"
      ]

    ; WriteString[client, ExportString[response, "HTTPResponse"]]

    ; Close @ client
    ]
  ]      
]

enter image description here

(* DeleteObject[server]
   Close[server["Socket"]]
*)

Very often SVG makes sense, it will scale well with magnification. This idea does not deserve a separate answer so additionally I rewrote the code in a more idiomatic style:

server = SocketListen[8000
, Function[{assoc}
  , Module[
      { client = assoc["SourceSocket"], inputString, response}

    , inputString = ImportString[assoc["Data"], "HTTPRequest"] @ "Query" // Lookup["expr"]

    ; response = HTTPResponse[
        ExportString[ToExpression[inputString], "SVG"]
      , <|"ContentType" -> "image/svg+xml"|>
      ]

    ; WriteString[client, ExportString[response, "HTTPResponse"]]

    ; Close @ client
    ]
  ]      
]

enter image description here

(* DeleteObject[server]
   Close[server["Socket"]]
*)

Very often SVG makes sense, it will scale well with magnification. This idea does not deserve a separate answer so additionally I rewrote the code in a more idiomatic style:

server = SocketListen[8000
, Function[{assoc}
  , Module[
      { client = assoc["SourceSocket"], inputString, response}

    , inputString = ImportString[assoc["Data"], "HTTPRequest"] @ "Query" // Lookup["expr"]

    ; response = GenerateHTTPResponse @ ExportForm[
        ToExpression[inputString], "SVG"
      ]

    ; WriteString[client, ExportString[response, "HTTPResponse"]]

    ; Close @ client
    ]
  ]      
]

enter image description here

(* DeleteObject[server]
   Close[server["Socket"]]
*)
Source Link
Kuba
  • 137.7k
  • 13
  • 289
  • 751

Very often SVG makes sense, it will scale well with magnification. This idea does not deserve a separate answer so additionally I rewrote the code in a more idiomatic style:

server = SocketListen[8000
, Function[{assoc}
  , Module[
      { client = assoc["SourceSocket"], inputString, response}

    , inputString = ImportString[assoc["Data"], "HTTPRequest"] @ "Query" // Lookup["expr"]

    ; response = HTTPResponse[
        ExportString[ToExpression[inputString], "SVG"]
      , <|"ContentType" -> "image/svg+xml"|>
      ]

    ; WriteString[client, ExportString[response, "HTTPResponse"]]

    ; Close @ client
    ]
  ]      
]

enter image description here

(* DeleteObject[server]
   Close[server["Socket"]]
*)