save jpg from a webserver
save jpg from a webserver
hi all!
I would like to save a jpg from a webserver to my pc. ip and port are fix.
This webserver is webcamXP http server and the page continuous are refreshing to load the new jpg picture in web browser.
Please help!
THX! (and I am a beginner programmer! :) )
I would like to save a jpg from a webserver to my pc. ip and port are fix.
This webserver is webcamXP http server and the page continuous are refreshing to load the new jpg picture in web browser.
Please help!
THX! (and I am a beginner programmer! :) )
-
- Posts: 1759
- Joined: May 23, 2007 21:52
- Location: Cut Bank, MT
- Contact:
-
- Posts: 8631
- Joined: May 28, 2005 3:28
- Contact:
the example getfile in fbnet.zip are only for TEXT and HTML sites but with short changes for pictures too.
here are the download: get: fbNet.zip
As beginner you must only know how the HTTP GET sequence looks for pictures.
Joshy
here are the download: get: fbNet.zip
As beginner you must only know how the HTTP GET sequence looks for pictures.
Joshy
Last edited by D.J.Peters on Jan 14, 2014 8:57, edited 3 times in total.
-
- Posts: 8631
- Joined: May 28, 2005 3:28
- Contact:
this is the right http get request
accept = "Accept: image/jpeg"
get my nice image :-)
Joshy
"getpicture.bas"
accept = "Accept: image/jpeg"
get my nice image :-)
Joshy
"getpicture.bas"
Code: Select all
#include "net.bi"
#define crlf chr(13) & chr(10)
dim as FDSOCKET hClient,hServer
dim as SOCKADDR_in ServerAddr,Iam
dim As HOSTENT ptr lpResolver
dim as string msg
dim as integer ret
dim as uinteger ip
dim as string servername="alice-dsl.net"
' create socket
hClient=NetSocket(AF_INET,SOCK_STREAM)
if hClient<0 then
? "error: create socket!"
sleep:end 2
end if
' get ip from server
lpResolver=NetGetHostByName (servername)
if lpResolver=0 then
? "error: NetGetHostByName!"
beep:sleep:end 3
else
ip=*lpResolver->h_addr_ip_list[0] 'server ip
end if
with ServerAddr
.sin_family = AF_INET ' protocol
.sin_port = htons(80) ' port 80 in network byte order
.sin_addr = ip ' server ip in network byte order
end with
' connect to server
ret=NetConnect(hClient,@ServerAddr)
if ret<0 then
? "error: can't connect to server!"
beep:sleep:end 4
end if
dim as string method,host,accept
method = "GET /d.j.peters/images/joshy.jpg HTTP/1.1" & crlf
host = "Host: alice-dsl.net" & crlf
accept = "Accept: image/jpeg" & crlf
msg = method & host & accept & crlf
ret=NetSendString(hClient,msg)
if ret<=0 then
? "error: send string!"
NetClose hClient
beep:sleep:end 6
end if
print "get file joshy.jpg please wait ..."
print "---------------------------------"
ret=NetReceiveString(hClient,msg)
' close the connection
NetClose hClient
if ret<0 then
? "error: get file/site!"
beep:sleep
else
dim as string header
dim as string image
ret =instr(msg,crlf & crlf) 'search for header terminator
header=left(msg,ret)
print header
print "---------------------------------"
ret+=3 ' jump over the header
image =right(msg,len(msg)-ret)
'optional save the answer
open exepath + "\joshy.jpg" for output as #1
print #1,image
close #1
print "file:" & exepath + "\joshy.jpg saved"
beep:sleep
end if
end
-
- Posts: 8631
- Joined: May 28, 2005 3:28
- Contact:
Wait you are talking about one webserver that writes 15 jpeg files per seconds and the same server sends you the curent picture after you made a http GET request?
i can't belive that
15 fps with compression normaly the result should be a video stream
i think a seperate video capture app. puts the pictures on the HD and the other app. the WEB server answers your http get requests.
while the capture app. writes a picture to the HD normaly the file is locked
the web server must wait before it can read it again.
(or the result will be an corrupt jpeg file)
curently you use:
do
__create socket
__get ip
__connect to server
__send one http request (close conection after transfer is the default mode)
__wait for answer
__close conection
__cut the jpg from transmision
loop
but it should be:
create socket
get ip
connect to server
send one http request (with keep alive mode)
do
__wait for answer
__cut the jpg from transmision
__send next http request
loop
send last http request (with close connection mode)
close socket
bla bla bla ;-)
Joshy
i can't belive that
15 fps with compression normaly the result should be a video stream
i think a seperate video capture app. puts the pictures on the HD and the other app. the WEB server answers your http get requests.
while the capture app. writes a picture to the HD normaly the file is locked
the web server must wait before it can read it again.
(or the result will be an corrupt jpeg file)
curently you use:
do
__create socket
__get ip
__connect to server
__send one http request (close conection after transfer is the default mode)
__wait for answer
__close conection
__cut the jpg from transmision
loop
but it should be:
create socket
get ip
connect to server
send one http request (with keep alive mode)
do
__wait for answer
__cut the jpg from transmision
__send next http request
loop
send last http request (with close connection mode)
close socket
bla bla bla ;-)
Joshy
thanks!! i will try....
oh, infos: this is a LAN server, the server made by WebcamXP. Tis software makes the pictures from a webcam. And refreshing for page...
And if i type to webbrowser the ip of this server i can see a page with a javascript that refreshing the jpg 15 times per second...
(the 10fps enought for me.)
i can try do it yourself.. but pf.. i am too stupid for network, http, get, and same things..
(sorry but I am a .... a beginner and the other is i think my english isn't the best...:) )
oh, infos: this is a LAN server, the server made by WebcamXP. Tis software makes the pictures from a webcam. And refreshing for page...
And if i type to webbrowser the ip of this server i can see a page with a javascript that refreshing the jpg 15 times per second...
(the 10fps enought for me.)
i can try do it yourself.. but pf.. i am too stupid for network, http, get, and same things..
(sorry but I am a .... a beginner and the other is i think my english isn't the best...:) )
-
- Posts: 8631
- Joined: May 28, 2005 3:28
- Contact:
-
- Posts: 8631
- Joined: May 28, 2005 3:28
- Contact:
there are only ip, : i type to browser this:
http://192.168.0.3:8080/cam_1.jpg
and i can see only the picture
if i type only http://192.168.0.1:8080 i can see the page , that automatic load the new jpg (15 per sec)
http://192.168.0.3:8080/cam_1.jpg
and i can see only the picture
if i type only http://192.168.0.1:8080 i can see the page , that automatic load the new jpg (15 per sec)
-
- Posts: 8631
- Joined: May 28, 2005 3:28
- Contact:
-
- Posts: 8631
- Joined: May 28, 2005 3:28
- Contact: