You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

pystache

Beginner

  • "pystache" is male
  • "pystache" started this thread

Posts: 6

Date of registration: Oct 22nd 2012

Location: France/Nantes

Occupation: Research...

  • Send private message

1

Monday, November 5th 2012, 7:01pm

micro server HTTP/HTML

Hi Jabaco team,
Very interesting platform !
For test i would make a microscopic HTTP/HTML server.
Searching on samples and tutorials, VB samples i am arrived to a first set with any Jabaco-newbe problems...
The index page is catched, but without picture and link not running. ?(
In fact microserver running i cant ask more than 1 time for my index page, the second time it crash. :cursing:
A zipfile is add and thanks for your help.
artimag
pystache has attached the following file:
  • Serveur4.zip (20.22 kB - 139 times downloaded - latest: Sep 12th 2018, 11:37pm)

PaulP

Beginner

Posts: 9

Date of registration: Nov 5th 2012

  • Send private message

2

Monday, November 5th 2012, 10:03pm

Hi, I used once Jetty (http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty) to set up a server and call it from Jabaco. I will post some code tomorrow. You need to build a jar wrapper in java to achieve that, but I will post one. Stay tuned.

PaulP

Beginner

Posts: 9

Date of registration: Nov 5th 2012

  • Send private message

3

Tuesday, November 6th 2012, 11:51am

As promised, here is a "proof of concept" code of embedding a Webserver in Jabaco.

You will need two jars to be added in "Project -> reference" (http://maven.eclipse.org/nexus/content/r…rvlet-2.5.0.jar and http://repo1.maven.org/maven2/org/eclips…7.v20120910.jar).

The launch button will start the embedded jetty server. Everything is done in pure java code, but interacting is possible by modifying the jar wrapper included (java source code is there too).

Main part of the java code of the wrapper :

Source code

1
2
3
4
5
6
7
8
9
public class Lanceur { 
 public void Lance(String word) 
{         try {            Server server = new Server(8080); 
 server.setHandler(new HelloHandler(word)); 
 server.start(); 
 server.join();
 }
 }
} 


To invoque the java code from Jabaco :

Jabaco Source

1
2
Dim MyWebServer As New com#mycompany#mavenproject1#Lanceur
MyWebServer.Lance("aString")



Enjoy !
PaulP has attached the following file:
  • embedsrv.zip (10.17 kB - 140 times downloaded - latest: Sep 11th 2018, 9:04pm)

pystache

Beginner

  • "pystache" is male
  • "pystache" started this thread

Posts: 6

Date of registration: Oct 22nd 2012

Location: France/Nantes

Occupation: Research...

  • Send private message

4

Wednesday, November 7th 2012, 1:07pm

winsock micro-server without picture-content and without link

Right Paul,
Wow i see your wrapper running well, with your jar samples. :thumbsup:
But i hope to use a maximum of Basic dialect and minus of Java (the Jabaco interest).
I have also seen in any sample the "java-way" to directly catch the java tools inline.
My problem today is : wy with my "micro-server" test-sample, i cant see the image content and wy the link is not running ? (on the index page well loaded on localhost). ;(
Thanks for your answer.
Pystache

PaulP

Beginner

Posts: 9

Date of registration: Nov 5th 2012

  • Send private message

5

Thursday, November 8th 2012, 4:30pm

RE: winsock micro-server without picture-content and without link

My problem today is : wy with my "micro-server" test-sample, i cant see the image content and wy the link is not running ? (on the index page well loaded on localhost). ;(

Hello, Pystache.

Well, the reason why the image is not showing is because in your code your are always serving the same file (index.html) whatever GET statement has been sent to your server...

I don't know the reason why the server hung after sending one file, but I could fix it on my computer by adding these lines in Sub Winsock1_SendComplete() :

For i = 1 To 100000
Next
List1.AddItem("Here We are") '--form1

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
Private Sub Winsock1_SendComplete()
'------------------------------------------------------ 
Winsock1.Close 
Winsock1.LocalPort = 80 
For i = 1 To 100000 
Next 
List1.AddItem("Here We are")  '--form1
On Error GoTo err3: 
Winsock1.Listen

Exit Sub


Regards,
PaulP

PaulP

Beginner

Posts: 9

Date of registration: Nov 5th 2012

  • Send private message

6

Thursday, November 8th 2012, 4:49pm

Another way to fix your problem is to move your Winsock1.Listen statement to a Winsock1_Close() sub...

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Private Sub Winsock1_SendComplete()
'------------------------------------------------------ 
Winsock1.Close 
Winsock1.LocalPort = 80
End Sub

Public Sub Winsock1_Close()

On Error GoTo err3: 
Winsock1.Listen

Exit Sub
'---------------------------------------------------------
err3: 
MsgBox "Port 80 already occupied.    ", vbCritical   '--browser 
End Sub

pystache

Beginner

  • "pystache" is male
  • "pystache" started this thread

Posts: 6

Date of registration: Oct 22nd 2012

Location: France/Nantes

Occupation: Research...

  • Send private message

7

Saturday, November 10th 2012, 4:19pm

micro-serveur news

In progress,
- with your winsock1_close : now the server doesnt crash ;
- loading now the files asked : the link are running and picture is "loaded".... but bad loaded ! :wacko:
New version is attached.
thanks for help
pystache
pystache has attached the following file:
  • Serveur5.zip (93.92 kB - 126 times downloaded - latest: Sep 10th 2018, 8:53pm)

PaulP

Beginner

Posts: 9

Date of registration: Nov 5th 2012

  • Send private message

8

Saturday, November 10th 2012, 7:25pm

Well done... Well the problem is that Strings in Jabaco are handled as Unicode ones... so at the very time you load characters upper ASCII-128 from a file into a String they get corrupted... Tried to help you by using <Reading and writing binary data> to read file, but I couldn't fix it... sorry...

My best results where by using "Winsock1.SendData(Fichier.readAll) ', but data is still corrupted by stupid unicode encoding of strings that I can't circumvent...

PaulP

Beginner

Posts: 9

Date of registration: Nov 5th 2012

  • Send private message

9

Saturday, November 10th 2012, 8:47pm

I got it fixed, but FGet.readFully is SLOW, I don't know why... try jpg file instead for better performance...

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Dim ErrString As String = "Error data, Error 404" & vbNewLine & "unknown file"
Dim MyFile As java#io#File 
MyFile = New File(App.Path & "\root" & lefich) 'Reading data 
Dim FChnl As java#io#FileInputStream 
Dim FGet As java#io#DataInputStream 
Dim Text() As Byte 
FChnl = New FileInputStream(MyFile) 
FGet = New DataInputStream(FChnl) 
Redim Text(0 To MyFile.length-1) 
List1.AddItem("- Taille du fichier = " & MyFile.length)  '--form1 
FGet.readFully(Text) 
List1.AddItem("- Taille du fichier = " & MyFile.length)  '--form1
On Error Goto Err2 
 Winsock1.SendData(Text) '--browser 
 FChnl.close 
 Exit Sub
'-----------------------------------------------------------
Err2: 
 Winsock1.SendData(ErrString) 
'--browserEnd 
Sub

PaulP

Beginner

Posts: 9

Date of registration: Nov 5th 2012

  • Send private message

10

Monday, November 12th 2012, 8:57am

For (drastically) better performance, I finally implemented readFileToByteArray from org#apache#commons#io#FileUtils (you need to download http://repo1.maven.org/maven2/commons-io/commons-io/2.4/commons-io-2.4.jar and to add it to you project : Project -> References -> add JAR file)

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
Dim ErrString As String = "Error data, Error 404" & vbNewLine & "unknown file"
Dim MyFile As java#io#File 
MyFile = New File(App.Path & "\root" & lefich)
Dim Text() As Byte
Redim Text(0 To MyFile.length-1)
Text = org#apache#commons#io#FileUtils.readFileToByteArray(MyFile)
List1.AddItem("- Taille du fichier = " & MyFile.length) '--form1 
On Error Goto Err2 
Winsock1.SendData(Text) 
'--browser 
Exit Sub

pystache

Beginner

  • "pystache" is male
  • "pystache" started this thread

Posts: 6

Date of registration: Oct 22nd 2012

Location: France/Nantes

Occupation: Research...

  • Send private message

11

Monday, November 12th 2012, 8:37pm

microserver more speed but a long way

Great speed! :thumbup: with video too ! but,
Unfortunately i obtain jabaco exception....
java.net.SocketException: Socket closed
at java.net.SocketOutputStream.socketWrite

(SocketOutputStream.java:116)
at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
at java.io.DataOutputStream.write(DataOutputStream.java:107)
at VB.WinsockSendThread.SendData(WinsockSendThread.jsrc)
at VB.WinsockSendThread.processData(WinsockSendThread.jsrc)
at VB.WinsockSendThread.run(WinsockSendThread.jsrc)
Maybe with my added link to video in page1. So killing iti always obtain:
java.lang.NullPointerException
at java.io.DataOutputStream.write(DataOutputStream.java:107)
at VB.WinsockSendThread.SendData(WinsockSendThread.jsrc)
at VB.WinsockSendThread.processData(WinsockSendThread.jsrc)
at VB.WinsockSendThread.run(WinsockSendThread.jsrc)
Where is my mistake? :?:
Other question: with this new jar, have we integrated a part of Apache kernel ?
with the last attached pack...without the video too big.
I am going to work with request-form and videos.
pystache
pystache has attached the following file:
  • microserver6.zip (21.92 kB - 142 times downloaded - latest: Sep 12th 2018, 4:42am)

PaulP

Beginner

Posts: 9

Date of registration: Nov 5th 2012

  • Send private message

12

Tuesday, November 13th 2012, 12:58am

Null pointer exception is due to the line "FChnl.close" (you should remove this, as Fchnl is not used anymore...)


Closed socket is hard to reproduce... It can happen if you cancel the connection from the browser I think. Checking for errors before opening the file could help.


You should also check that requested file exist, otherwise you will get an error message...

Rate this thread
WoltLab Burning Board