开发者

how to receive a vlc flow in a socket?

开发者 https://www.devze.com 2023-01-08 18:25 出处:网络
I\'m developping a streaming application with tcl. I have a vlc sever that broadcast a flow in http mode. what I\'m trying to do is to develop a client开发者_如何学编程 who will try to connect to serv

I'm developping a streaming application with tcl. I have a vlc sever that broadcast a flow in http mode. what I'm trying to do is to develop a client开发者_如何学编程 who will try to connect to server with a particular ip adress and port number, and then try to save the flow in a file. the code that i'm using is simple:

set server localhost
set sockChan [socket $server 1234]
set line [read $sockChan 1000]
puts " vidéo: $line"
close $sockChan

the problem when i try to test my script, I see that I realise the connection, but I can't read the flow! the 'puts' doesn't show anything in the console...

Have you any ideas! thank you..


If you're just wanting to save the contents of a URL to a file, the standard http package has a -channel option which lets you dump directly. For example:

package require http
set f [open video.dump w]
fconfigure $f -translation binary
set tok [http::geturl "http://server:port/url" -channel $f]
close $f
if {[http::ncode $tok] != 200} {
    # failed somehow...
} else {
    # succeeded
}
http::cleanup $tok

Edit: Doing it asynchronously (requires the event loop going, e.g. via vwait forever):

package require http
set f [open video.dump w]
fconfigure $f -translation binary
proc done {f tok} {
    close $f
    if {[http::ncode $tok] != 200} {
        # failed somehow...
    } else {
        # succeeded
    }
    http::cleanup $tok
}    
http::geturl "http://server:port/url" -channel $f -command "done $f"
# Your code runs here straight away...

Note that the code's recognizably similar, but now in a slightly different order! If you've got Tcl 8.5 — if not, why not? — then you can use a lambda application instead to make the apparent order of the code even more similar:

package require http
set f [open video.dump w]
fconfigure $f -translation binary
http::geturl "http://server:port/url" -channel $f -command [list apply {{f tok} {
    close $f
    if {[http::ncode $tok] != 200} {
        # failed somehow...
    } else {
        # succeeded
    }
    http::cleanup $tok
}} $f]
# Your code runs here straight away...


Since you are working with HTTP, I would suggest looking at libcurl bindings for TCL.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号