This function WEBSERVER, is a HTTP webserver for HTML code and images and also allows execution of Matlab code through the web.
- HTML and images
- Upload files
- M file execution
% Use firefox or internet explorer and visit http://localhost:4000/
Dirk-Jan Kroon (2021). Web Server (https://www.mathworks.com/matlabcentral/fileexchange/29027-web-server), MATLAB Central File Exchange. Retrieved .
Matlab GUI / Figure can be achieved in Web Server?
Thanks since now for your help!
Hey I am very new to MATLAB. I found this useful piece of code. Please tell me what should the variable 'config' be declared?
I try to make the webserver run a M file, but webserver(4000, 'file.m') doesn't make it ...
Did I misunderstand something ?
I don't know if I really understand the purpose of this webserver, but I have my own website and would like to allow people (my website's visitors) to run little funny Matlab scripts or commands directly on my website. µ
Can I use such webserver to do that ?
Hi. Thanks for this nice application. I have a problem in photo uploading. I select an image named 1.jpg. Whatever I write in box "Title of your Image", I get the following error after sending:
Error using fwrite
Invalid file identifier. Use fopen to generate a valid file identifier.
I went through the code and it seems that it doesn't save the image in any folder. Then, it creates a random number and assigns it to the image's name. But , finally, it can't find the image. (see file multipart2struct.m, lines36 to 41).
How can I solve this problem?
This webserver is fantastic. Using it to provide some MATLAB analysis functions to co-workers.
Does this support serving css or am I missing something? I don't seem to be able to use it.
Hi, A favour, when I write in portuguese language some letters (for example: ç,õ,í,á, ) does not appear when the text arrives to the matlab. How can I resolve it?
I thank you since now for your help.
Wish MATLAB could be used for web application like other framework e.g., web2py. This submission shows its possible to use MATLAB as a front end for the framework. Wondering if any plans to move fwd to something bigger, like ORM for django?
This software is only a small demo I wrote for fun, and never tested with more than one user.
Probably it is also not really suitable for multiple users, because Matlab is in basis single threaded.
A solution is using a real HTTP server like Apache, in combination with PHP (see easyphp.org).
Then compile your matlab-code to a executable and simply parse the user inputs/outputs to that executable through PHP.
Thank you again for creating this fantastic tool. It will have a very big impact on our progress.
Question: Is there a way to decrease response latency from the server? We have the server up and running, but we are getting latencies to serve a simple page of about 1 second at no load, and up to 10 seconds at larger numbers of users (still pretty modest numbers in the tens of concurrent users). We would like to use it with a capacity to handle about 100 concurrent users with latencies <1second. Is this possible? Will running on a faster machine, compiling, or other approaches lead to this outcome? Thank you very much for your help.
It turns out that the post below from 30 Mar 2014 saying that the webserver was not working results from the fact that the webserver doesn't work with Matlab2007b. On newer Matlab versions webserver works fine (2010, 2014).
Thanks for contributing, as this looks like it could be an important application for us.
Unfortunately, so far the code is not working for me. Help would be greatly appreciated.
I downloaded and unzipped the files and subfolders into a directory, went to that directory in matlab, and typed the sample commands, eg webserver(4000) or webserver(4000,config) after setting up config variable. The webserver seemed to have started, and created a figure window. I then went to chrome and firefox and typed http://localhost:4000, but I got the error that the connection timed out / no data received. I tried again with port 4001, same error. This is on a windows pc. Note this is with Matlab 2007b. Thanks for your help.
How can i get the Multipart POST to work for binary data that i'm sending? I'm not sending a file but a 8 bit grayscale PNG image byte array. The code is failing completely in text2header. Is this even supported?
Where would I go about placing my own m file for execution within the code, as in which .m file would I place the call under?
Very useful. Thank you.
Please note I had to split:
into 2 lines:
To avoid the error:
Static method or constructor invocations cannot be indexed.
Do not follow the call to the static method or constructor with
any additional indexing or dot references.”
This is just perfect in every manner. Awesome piece of code that is well designed and works perfectly :-)
Great work, thanks a lot.
A Matlab GUI/Figure is user-interface thus client-side, this is a webserver thus server-side.
i'm trying to use this to put a matlab gui on a web page. However, i'm stubling on how to call the .m file to call the gui. Can you help me on how to do this?
Excellent work with many useful applications.
Anyway I experienced one problem and I hope you can help me to understand how to solve it.
Web server application runs very well on my laptop (Matlab188.8.131.526 (R2010b) SP1), but when I try to run in my virtual machine (Matlab184.108.40.206 (R14) SP3) the server starts, but when I try to connect the brower start to load the page but it stops and the display message is the following:
Webserver Available on http://localhost:4000/
GET / HTTP/1.1
Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/xaml+xml, */*
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET4.0C)
Accept-Encoding: gzip, deflate
Get: [1x1 struct]
Content: [1x1 struct]
HTTP/1.0 200 OK
Date: Tue, 12 Oct 2010 09:19:05 GMT
Server: Matlab Webserver
X-Powered-By: Matlab220.127.116.11 (R14) Service Pack 3
Set-Cookie: SESSID=5322082bf473207961031e3df1f45a22; path=/
Expires: Thu, 19 Nov 1980 08:00:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Content-Type: text/html; charset=UTF-8
I tried to locate the source of the problem and it seems that after the first while(true) the script enter in:
and it get stuck into:
try socket = TCP.serverSocket.accept; break; catch, end
if(~ishandle(TCP.stopwindow)), TCP.socket=-1; return, end
Any suggestion is very welcomed!
Does this need appach or IIS?
Excelent piece of code, very useful !
Hi.. how do I automatically reset the webserver whenever I encounter this error:
Java exception occurred:
java.net.SocketException: Software caused connection abort: socket write error
That is, I dont need to go to matlab and re-run webserver(80) manula in the command window.
Very nice piece of code. It works very well for me.
Very interesting, I will test this, I've made php-console bridge on linux...
I can confirm it works well.
Today I uploaded the version which solves your problems (will probably be online tomorrow) ...
Thank you for your comments.
The Java-error is due to earlier usage of the port without correctly closing/disconnecting the port due to a code-crash or other problem. In the future I will probably try to solve that by storing the port in a Matlab global, making it possible to close the port after a code crash.
I didn't experience the refresh problems my self. But the code is very experimental, and still more like a prove of concept. Hopefully i will find time to improve the code in the near future, or maybe somebody else will create his own project from this with more stable code.
It's interesting project apart some stability problems.
The following message is often displayed (when i launch webserver first time, it's ok. If i stop it and run it again, it's rain of messages) :
??? Java exception occurred:
java.net.BindException: Address already in use: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(Unknown Source)
at java.net.ServerSocket.bind(Unknown Source)
at java.net.ServerSocket.<init>(Unknown Source)
at java.net.ServerSocket.<init>(Unknown Source)
Error in ==> JavaTcpServer at 10
serverSocket = ServerSocket(data);
Error in ==> webserver at 33
Other problem, i must refresh sometimes until almost 10 times before the server executes my url.
If you have any suggestion to improve the stability, I'm very interested.
Inspired: Simple Network Information Server (SNIS)
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!