All socket exceptions are thrown from the underlying runtime and represent messages from the operating system. When operating with the network, the rest server is calling the operating system to open a port and SocketExceptions are the answer from the operating system when something goes wrong.
In the case of duplicate usage there are multiple error sources:
Every operating system has ways to find out which port is used by which software, for example with netstat
. For Windows
there is also a GUI tool like this.
From the rest server there is no workaround for these problems, and they must be mitigated by the developer.
The plugin needs the .NET compatibility set to newer C# versions. Usually when you get compilation errors, the “API Compatibility Level” is set to “.NET Standard 2.0”. Please set it to “.NET 4.x” or newer.
If you still encounter problems, please feel free to contact me.
Please make sure that you fulfill these requirements:
If the Rest Server nodes are still not showing up, please regenerate Visual scripting nodes:
The rest server nodes should now be accessible. If you still encounter problems, please feel free to contact me.
The make the server available make the rest server listen on all IPv4 interfaces. After you enter playmode and start the server, all listening ips are displayed
When calling the endpoint,
It is technically possible to register the same endpoint path multiple times. Which endpoint implementation will be executed is undefined. The rest server will issue a warning when a duplicate endpoint is registered.
There are cases where duplicates can not be identified beforehand. This is the case when using endpoints with Regex definitions. Make sure that the Regex definitions do not overlap to have a stable endpoint resolution on each call.
The rest server main focus is handling REST interfaces which consist of JSON, XML or similar formats. The underlying library provides methods to access the binary data of the request itself and the rest server exposes this (for example the BodyBytes property on the RestRequest class). The HTTP standard itself defines multiple and various methods on how to transmit binary data, which may need custom parsing.
If there is the need to handle binary data, there are few ways to accomplish this, which are described in the next sections
The binary data can be base64 encoded by the client and sent to the server. Either the body is completely base64 encoded or the base64 encoded binary data is included in a json structure. On the server side C# methods can be used to convert base64 back to binary, like this
var data = Convert.FromBase64String(request.Body)
In this variant the request body is the uploaded file directly/raw. This can easily be achieved when the client is a JavaScript application and/or a custom application where the request can be controlled completely. The binary body data can be accessed in the request via this method
var data = request.BodyBytes
Multipart/form-data is the default HTML upload method when using forms in browsers. It is also the most complicated as multiple files can be uploaded with the same request and the body follows a complicated structure. It is outside the scope of the rest server library to provide a full parser for this as there are already advanced open source libraries that do this.
Nevertheless, the rest server includes a very simple parser to parse very simple multipart/form-data requests. See the Static Content Example.
List<MultiFormDataElement> uploadData;
try {
uploadData = new SimpleMFDParser().Parse(request);
}
catch (SystemException e) {
request.CreateResponse().InternalServerError("No form data found.").SendAsync();
return;
}
var data = uploadData[0].Data;
This alternative variant doesn’t upload files directly, but uses a third party service to upload files to the rest server. This might be a good solution if the data to upload is very large.
A third party service is used and the client uploads the files to the third party service. Upon completion the client informs the server that the file has been uploaded and under which url the file can be downloaded. The server continues to download the file from the third party service. With this method no upload to the rest server is done directly.
Examples could be AWS S3 buckets, AWS S3 pre-signed uploads and others.