forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Please help me with VDSINET

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
bornsoft
Contributor
Contributor


Joined: 19 Feb 2009
Posts: 113
Location: Germany

PostPosted: Sun Nov 07, 2010 1:31 am    Post subject: Please help me with VDSINET Reply with quote

Hi

now I've spent two days with finding a way to transfer binary files via TCP sockets with VDSINET.DLL and could not get it workin properly.

I'm working on a small HTTP-Server, the code below is not the complete one, it's reduced to the part i have the problem with. Serving all kinds of text-based files works perfect, but all binary files like grafics etc. are krippled by "NET SOCKET,SendID," command.

I hope someone here has got an idea what I can do to get it working.

Interesting observation is, that the received data is complete different depending on how many bytes are sent at a time. The smaller the number of bytes sent, the more are received. But even if I send only one byte a time not all are received correctly.

I know, there is a VDSHTTPd extension out here that works with grafics but it's not able to work with cgi-tasks, thats why I wanna make my own server.

I've also tried VDSIPP but with this i was not able to receive the complete request-header.

To test this script put a file "index.html" and any binary file like jpg or gif into the same directory, run the script and type into your browser "http://localhost" or e.g. "http//localhost/<filename>.jpg".

Thank you in advance and greetings.

bornSoft

Here is the code:

Code:

  Title bsHTTP-Server

  option decimalsep,.

  #DEFINE Function,NET
  #DEFINE Command,NET

  #DEFINE Command,LogList
  #DEFINE Function,FindFile
  #DEFINE Function,MimeType

  EXTERNAL @path(%0)vdsinet.dll,Public Freeware Key|90257236

  %%Root = @substr(@path(%0),1,-1)
  %%DefaultDoc = index.html
  %%ServerName = bsHTTP-Server
  %%ServerDateTime = "Sat, 06 Nov 2010 09:18:15 GMT"

  DIALOG CREATE,%%ServerName,-1,0,370,260,ONTOP
  DIALOG ADD,LIST,LogList,4,4,362,230
  DIALOG ADD,STATUS,STATUS,
  DIALOG SHOW

  #    HScroll on LogList                         
  %z = @sendmsg(@winexists(~LogList),$0194,1000,0)

  NET SOCKET,AUTO
  NET SOCKET,PORT,80
  NET SOCKET,SERVER
  NET SOCKET,VDSEVENTS

:EvLoop
  wait 0.01
  %E = @event()
  if %E
      goto %E
  end
  %E = @NET(SOCKET,Event)
  if @equal(%E,NETWORK)
      goto Request
  end
  goto EvLoop

:Close
  NET SOCKET,Close
  exit

#    Incoming Request         
:Request
  %%Request = @NET(SOCKET,Data)
  if @not(@null(%%Request))
      %%ID = @NET(SOCKET,SenderID)
      %%IP = @NET(SOCKET, SenderAddr)
      option fieldsep,@chr(32)
      parse "%%Method;%%URI;%%HTTP",%%Request
      %%HTTP = @substr(%%HTTP,1,8)
      LogList [@datetime(dd.mm.yyyy - hh:nn:ss)]@tab()ID: %%ID@tab() Address: %%IP
      LogList @tab()REQUEST: %%Method %%URI %%HTTP
      goto Method_%%Method
  end
  goto evloop

:Method_GET
  %%File = @FindFile(%%URI)
  if @not(%%File)
      %%ResponseStatus = %%HTTP" 404 Not Found"
      %%ContentLength = 0
    else
      %%ResponseStatus = %%HTTP" 200 OK"
      %%ContentLength = @file(%%File,z)
  end
  %%Response = %%ResponseStatus@cr()@lf()
  %%Response = %%Response%%ServerDateTime@cr()@lf()
  %%Response = %%Response"Server: "%%ServerName@cr()@lf()
  %%Response = %%Response"Content-Length: "%%ContentLength@cr()@lf()
  %%Response = %%Response"Content-Type: "@MimeType(%%File)@cr()@lf()
  %%Response = %%Response@cr()@lf()
  NET SOCKET,SendID,%%ID,%%Response

  if %%File
      %F = @new(File,%%File,Read)

      repeat
 #         NET SOCKET,SendID,%%ID,@read(%F,256)
          NET SOCKET,SendID,%%ID,@read(%F,1)
          dialog set,Status,Event: @net(SOCKET,EVENT)
      until @filepos(%F,EOF)

      closefile %F

  end

  NET SOCKET,CloseCID,%%ID

  LogList @tab()RESPONSE: %%ResponseStatus
  goto EvLoop

:LogList
  list add,LogList,%1
  #    Scroll visible     
  %x = @sendmsg(@winexists(~LogList),$197,@pred(@count(LogList)),0)
  exit

:FindFile
  if %1
      %1 = @strrep(%1,/,\,all)
      if @equal(%1,\)
          %R = %%Root\%%DefaultDoc
        else
          %1 = @strdel(%1,1)
          %R = @file(%%Root\%1)
      end
  end
  exit %R

:MimeType
  if %1
      if @equal(@ext(%1),html) @equal(@ext(%1),htm)
          %R = "text/html; charset=iso-8859-1"
        elsif @equal(@ext(%1),jpg) @equal(@ext(%1),jpeg)
          %R = "image/jpg"
        elsif @equal(@ext(%1),gif)
          %R = "image/gif"
        elsif @equal(@ext(%1),png)
          %R = "image/png"
        else
          %R = "file/unknown"
      end
    else
      %R = "file/unknown"
  end
  exit %R



.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group