Socket and Web server Not Working

Socket and Web server Not Working

Postby johnshay » Tue Sep 25, 2012 5:11 pm

Hi. I am trying to implement a web Server on my pocket PC. I have used the xWebServer Class from FWHarbour and it Almost Works! The problem i Have is the Sever request work fine Once...but then it wont accept a request again until i Exit and Restart the Program. The problem seems to be with Sockets and so i tested using a very simple bit of socket server code from the Harbour examples. Sure enough this works fine for the first connection. I am just using a WEB Browser on a PC and listening on PORT 80 on the Pocket PC. I send some data back and voila - it appears in the PC web Browser. BUT when i try again (i just refresh the page) it wont work! Something is getting corrupted or closed when it shouldnt be. I assume there must be some diffefence is API for Big Windows and winCE..Have there been any re-writes or the SOCKET class in recent versions?? I am using FEB2010 FWPPC Build... Please Help...Thanks

Code Example
Code: Select all  Expand view  RUN
 oSocket = TSocket():New(80 )
   oSocket:bAccept = { | oSocket | oClient := TSocket():Accept( oSocket:nSocket ),;
                       oClient:Cargo := 0,;
                       oClient:bRead := { | oSocket | OnRead( oSocket ) },;
                       oClient:bClose := { | oSocket | OnClose( oSocket ) } }

   oSocket:Listen()

ACTIVATE WINDOW ownd
   close all

return nil



function OnRead( oSocket )

   local cData := oSocket:GetData()
   local cToken
   msginfo(cData)
   cbuffer=" HELLO "
          oSocket:SendData( "HTTP/1.0 200 OK" + CRLF + ;
                                       "Server: FiveWin WebServer 1.0" + CRLF + ;
                                       "Content-type: text/html" + CRLF + ;
                                       "Content-length: " + Str( Len( cBuffer ) ) + CRLF + ;
                                       "" + CRLF + cBuffer )
                                      // oSocket:close()
return nil

//------------------------------------------------------------------------//
User avatar
johnshay
 
Posts: 10
Joined: Mon Mar 10, 2008 11:46 am
Location: Manchester,UK

Re: Socket and Web server Not Working

Postby Antonio Linares » Wed Sep 26, 2012 6:11 am

John,

Instead of doing a MsgInfo( cData ), better use a LogFile( "events.txt", { cData } ) and check if you get the next requests

Also keep in mind that a proper Web server would need to use threads, so if you plan to implement a truly Web server attending multiple clients, it won't work as expected and surely will not be able to attend all requests.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42111
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Socket and Web server Not Working

Postby johnshay » Wed Sep 26, 2012 8:39 am

Hi Antonio,
Yes the MSGINFO was just a quick n dirty way for seeing what text the Browser sent. Iv tried it without and it still only works the once..BUT I have it working on another unit running WINCE5.0 so i guess its a problem in WINCE6.
Do you know if they changed the socket API for WINCE6 or added a firewall or something. Its really frustrating as i am so near and yet so far....
I have to use WINCE6 as i cant change the units. Could anyone else test this on there devices???
It Works pefectly on the first CALL but then no other requestes are received/responded to...Any Ideas ?
Thank you
john
User avatar
johnshay
 
Posts: 10
Joined: Mon Mar 10, 2008 11:46 am
Location: Manchester,UK

Re: Socket and Web server Not Working

Postby Antonio Linares » Wed Sep 26, 2012 10:21 am

regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42111
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Socket and Web server Not Working

Postby Antonio Linares » Wed Sep 26, 2012 10:32 am

John,

An idea could be to replace winsock.dll in WinCE 6 with the Winsock.dll from WinCE 5
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42111
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Socket and Web server Not Working

Postby johnshay » Wed Sep 26, 2012 11:14 am

Yes iv even found a few posts in this forum from people who get a GPF error when trying to open a socket. BUT i dont have any other problems. Nothing is crashing. Network on the ce device still works. Ip address renew works. It just wont accept another onRead event. Am i right in assuming 2 sockets are used. The first one is created and listens for a request. When one arrives another socket is created which handles the data. This one gets closed but the First Listening socket should continue and receive other requests? I added a log to onread event and i can see that it is this which is only firing once.
I though about just copying winsock.dll from the ce5 device - But i remember reading that the Kernel was re-written in CE6 and works using a different memory model, so its unlikely to work on CE6 with a CE5 dll. But i will try it anyway. Also there seems to be another dll - WS2.dll which microsoft released and has extra functionality. Is it possible to modify the Library to call WS2.dll instead of winsock.dll or does the os itself decides which dll get called?

Also the device i am using had the Microsoft web server HTTP.dll installed. Obviousley i have stopped this service so that my fivewin prog gets the Port 80 Socket.
If i re-enable and use the Built in server, this works repeatedly so i am assuming its not a bug in winsock just the way its being used/called in wifewin in CE6

The reason for the Server is to pass data from DBF files to browser is JSON or XML style. I can use the build in WINCE server to serve pages but not to get DBF data, so I'm a little stuck at the mo....Any help but be very appreciated
john
User avatar
johnshay
 
Posts: 10
Joined: Mon Mar 10, 2008 11:46 am
Location: Manchester,UK

Re: Socket and Web server Not Working

Postby Antonio Linares » Wed Sep 26, 2012 11:24 am

John,

As you have explained, the same EXE is working fine on WinCE 5 and fails on WinCE 6. So it seems as a WInCE sockets issue.

When you build the EXE, you link a MS lib that allows to use sockets: \lib\arm\winsock.lib

if you use there a different lib then you will be able to use a different sockets dll. winsock.lib is an import library for winsock.dll

Maybe there is a compatible DLL with winsock.dll. Just guessing. This is the first time that we are reported about this :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42111
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Socket and Web server Not Working

Postby johnshay » Wed Sep 26, 2012 1:28 pm

yes..I see now. Well iv been trying various thing for the past 24hours now and just cant seem to get it to work. Its not a problem in Fivewin its WINCE6 on the device i have. I dont think i will find a solution BUT i have managed to get it to work as a Client instead of a server. I am going to 'POLL' a server socket on a PC or on the www and communicate that way. Iv done some testing and it seems to work. Now i need to readup on HTML5 web sockets to see if i can have a listeneing socket in Javascript..
Thanks for your replies Antonio and congrats on a great product. Do you have anything new in development? Iv noticed your work on android/iphone..How about Five-Rapberry-PI ... lol
User avatar
johnshay
 
Posts: 10
Joined: Mon Mar 10, 2008 11:46 am
Location: Manchester,UK

Re: Socket and Web server Not Working

Postby Antonio Linares » Wed Sep 26, 2012 1:57 pm

Here are IDC's figures for worldwide smartphone unit sales and market share in the second quarter of 2012, by operating system.
— Android (Google Inc.) — 104.8 million units, 68.1 percent share (46.9 percent a year earlier)
— iOS (Apple Inc.'s iPhone) — 26.0 million units, 16.9 percent share (18.8 percent a year earlier)
— BlackBerry (Research in Motion Ltd.) — 7.4 million units, 4.8 percent share (11.5 percent a year earlier)
— Symbian (mostly used by Nokia Corp.) — 6.8 million units, 4.4 percent share (16.9 percent a year earlier)
— Windows (Microsoft Corp.) — 5.4 million units, 3.5 percent share (2.3 percent a year earlier)
— Linux — 3.5 million units, 2.3 percent share (3.0 percent a year earlier)
— Others — 0.1 million units, 0.1 percent share (0.5 percent a year earlier)


It seems that we should focus on Android and iOS
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42111
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Pocket PC

Who is online

Users browsing this forum: No registered users and 5 guests