so che e' un po' ardua ..... ma come e' che questo codice (benche' si connetta al server) non genera eventi?
' Gambas module file
'
Private TcpConnection As New Socket 'connessione tcpip
Private hTim As Timer 'timer per il timeout
Public Channel_name As String
Public Refresh_Time As String
Public DB_server_IP As String
Public DB_server_Port As String
Public DB_server_DBuser As String
Public DB_server_DBpass As String
Public DB_server_DBname As String
Public MLT_server_IP As String
Public MLT_server_Port As String
'la struttura del singolo RECORD dei video (similare per gli spot)
Public Struct Media
channel As String
data As Date
start_time As String
end_time As String
programma As String
stagione As String
episodio As String
fullpath As String
loaded As Boolean
transmitted As Boolean
mark_in As String
mark_out As String
id As Integer
End Struct
'il VETTORE che contiene i record
Private Mediaplaylist As New Media[]
'la struttura del singolo RECORD degli SPOT
Public Struct Spot
channel As String
data As Date
tempo As String
committente As String
campagna As String
spotname As String
fullpath As String
loaded As Boolean
transmitted As Boolean
priority As Integer
id As Integer
End Struct
'il VETTORE che contiene i record
Private Spotplaylist As New Spot[]
'------------------------- questo il lancher per il demone
' #! / Bin / bash
' #lancia il demone con i necessari parametri
'
' #setta il carattere di separazione speciale a % e non lo spazio
' IFS = '%'
'
' #il nome del canale che devo riprodurre(per vedere i contenuti che mi competono)
' channel_name = 'Tele Galileo'
'
' #frequenza di aggiornamento della playlist In minuti(meglio non meno di 30)
' refresh_time = 30
'
' #parametri d 'accesso al server di database
' #db_server_ip = localhost
' db_server_ip = 192.168.1.91
' db_server_port = 3306
' #db_name = OTVA
' db_name = OTVA_test
' db_user = OTVA_user
' db_password = OTVA_password
'
' #parametri d 'accesso al server Miracle (Melted)
' mlt_server_ip = localhost
' mlt_server_port = 5250
'
' . / xml_demon.gambas $channel_name $refresh_time $db_server_ip $db_server_port $db_name $db_user $db_password $mlt_server_ip $mlt_server_port
'---------------------------------------------------------------
'Public tempo As Timer
Public Sub Main()
' This reads and displays the command line parameters
Dim l As Integer
Dim numparms As Integer
Dim parm As String
numparms = Application.Args.Count
For l = 0 To numparms - 1
parm = Application.Args[l]
Select Case l
Case 0
'nome dellapplicazione ... ma non ci interessa
Case 1
Channel_name = parm
Case 2
Refresh_Time = parm
Case 3
DB_Server_IP = parm
Case 4
DB_server_Port = parm
Case 5
DB_server_DBname = parm
Case 6
DB_server_DBuser = parm
Case 7
DB_server_DBpass = parm
Case 8
MLT_server_IP = parm
Case 9
MLT_server_Port = parm
End Select
'Print "[" & l & "]" & parm & gb.crlf
Next
Print "OTVA deamon for channel: " & Channel_name & gb.Tab & gb.CrLf & "DB_server: " & DB_Server_IP & ":" & DB_server_Port & gb.CrLf &
"DB_account: " & DB_server_DBuser & ":" & DB_server_DBpass & gb.CrLf &
"refresh frequency: " & Refresh_Time & " minutes" & gb.CrLf &
"Melted server: " & MLT_server_IP & ":" & MLT_server_Port & gb.CrLf
'connect to db and extract data from MEDIA Playlist
GetMediaPlaylist()
Print "ci sono " & Mediaplaylist.Count & " media in lista"
'
'connect to db and extract data from SPOT Playlist
GetSpotPlaylist()
Print "ci sono " & Spotplaylist.Count & " spot in lista"
'
'connect to MELTED server and check what WAS transmitted, what is in play and what have to be trasmitted.
GetMeltedServerStatus()
'
'check for event
'
'play requested media
End
Public Sub TcpConnection_Read()
'****************************************
' When some data arrives from the remote
' part of the socket, "DataAvailable" event
' is raised
'****************************************
Dim S As String
Print "reading from server" & gb.CrLf
If TcpConnection.Status = Net.Connected Then
Read #TcpConnection, S, Lof(TcpConnection)
Print S
End If
End
Public Sub TcpConnection_Error()
Select Case TcpConnection.Status
Case Net.CannotCreateSocket
Print "The system does not allow to create a socket"
Case Net.HostNotFound
Print "Host not Found"
Case Net.ConnectionRefused
Print "Unable to Connect. Connection Refused"
Case Net.CannotRead
Print "Error Reading Data"
Case Net.CannotWrite
Print "Error Writing Data"
End Select
End
Public Sub GetMeltedServerStatus()
'se melted server non e' in esecuzione mando una email al sistemista ed esco
hTim = New Timer As "Timer1"
hTim.Delay = 10000 '10 secondi di timeout
hTim.Enabled = True 'poi aspetto per il time out
TcpConnection.Host = MLT_server_IP
TcpConnection.Port = MLT_server_Port
Print "tentativo di connessione ..."
TcpConnection.Timeout = 10
TcpConnection.Connect()
'TcpConnection.Connect(MLT_server_IP, MLT_server_Port)
Do
Wait 'aspetto indefinitamente MA LASCIO CHE GLI EVENTI SI GENERINO
Loop Until (TcpConnection.Status = Net.Connected) Or (hTim.Enabled = False) 'aspetto finche' vado in timeout o la connessione restituisce qualcosa
If hTim.Enabled = False Then
Print "connessione al server melted non riuscita (TIME OUT)!" & gb.CrLf & "Contattare l'amministratore !!!!"
'send email to admin
Quit
Endif
hTim.Stop 'stoppa comunque il timer
If TcpConnection.Status <> Net.Connected Then
Print "connessione al server melted non riuscita!" & gb.CrLf & TcpConnection.Status & gb.CrLf & "Contattare l'amministratore !!!!"
'send email to admin
Quit
Else
Print "connessione al server melted RIUSCITA!"
Endif
'sono connesso e controllo il suo stato
TcpConnection.Begin
Print TcpConnection.Peek
'dopo di che chiudo la connessione. PS: rimaneva appiccato perche' non chiudevo la connessione tcp :D
TcpConnection.Close
End
Public Sub Timer1_Timer()
hTim.Enabled = False
End
Public Sub GetSpotPlaylist()
Dim ComandoPlaylist As String = "select * from SpotPlaylist where channel = '" & Channel_name & "' and date = '" & Format(Date, gb.ShortDate) & "' order by time"
'se vuoi l'ordinamento decrescente usa order by nome tabella poi DESC
Dim SingoloSpot As New Spot 'il singolo SPOT che estraggo dal DB
Dim $Con As New Connection
Dim Risultato As Result
$Con.close() ' Close the connection
$Con.Type = "MySQL" ' Type of connection
$Con.Host = DB_server_IP ' Name of the server
$Con.Login = DB_server_DBuser ' User's name for the connection
$Con.Port = DB_server_Port ' Port to use in the connection, usually 3306
$Con.Name = DB_server_DBname ' Name of the database we want to use
$Con.Password = DB_server_DBpass ' User's password
'carico i programmi come root del treeview
Print ComandoPlaylist
Try Risultato = $Con.Exec(ComandoPlaylist)
If Error Then
Print "Failed 'GetSpotPlaylist' procedure." & gb.CrLf & "Impossible to connect to db [" & Error.Text & "]"
Quit
Endif
'svuoto la lista dei contenuti
Spotplaylist.Clear
For Each Risultato
With SingoloSpot
.channel = risultato!channel
.data = risultato!date
.tempo = risultato!time
.committente = risultato!committente
.campagna = risultato!campagna
.spotname = risultato!spotname
.fullpath = risultato!fullpath
.loaded = risultato!loaded
.transmitted = risultato!transmitted
.priority = risultato!priority
.id = risultato!id
End With
Spotplaylist.Add(SingoloSpot)
Next
End
Public Sub GetMediaPlaylist()
Dim ComandoPlaylist As String = "select * from MediaPlaylist where channel = '" & Channel_name & "' and data = '" & Format(Date, gb.ShortDate) & "' order by start_time"
'se vuoi l'ordinamento decrescente usa order by nome tabella poi DESC
Dim SingoloEpisodio As New Media 'il singolo episodio che estraggo dal DB
Dim $Con As New Connection
Dim Risultato As Result
$Con.close() ' Close the connection
$Con.Type = "MySQL" ' Type of connection
$Con.Host = DB_server_IP ' Name of the server
$Con.Login = DB_server_DBuser ' User's name for the connection
$Con.Port = DB_server_Port ' Port to use in the connection, usually 3306
$Con.Name = DB_server_DBname ' Name of the database we want to use
$Con.Password = DB_server_DBpass ' User's password
'carico i programmi come root del treeview
Print ComandoPlaylist
Try Risultato = $Con.Exec(ComandoPlaylist)
If Error Then
Print "Failed 'GetMediaPlaylist' procedure." & gb.CrLf & "Impossible to connect to db [" & Error.Text & "]"
Quit
Endif
'svuoto la lista dei contenuti
Mediaplaylist.Clear
For Each Risultato
With SingoloEpisodio
.channel = risultato!channel
.data = risultato!data
.start_time = risultato!start_time
.end_time = risultato!end_time
.programma = risultato!stagione
.episodio = risultato!episodio
.fullpath = risultato!fullpath
.loaded = risultato!loaded
.transmitted = risultato!transmitted
.mark_in = risultato!mark_in
.mark_out = risultato!mark_out
.id = risultato!id
End With
Mediaplaylist.Add(SingoloEpisodio)
Next
End
ho guardato l'esempio nell'IDE di Gambas (socket client), ma qui' addirittura non ho visto DOVE E' DEFINITO l'oggetto MySocket
essendo il mio un programma consolle ho difficlta' a fare il debugging visuale, ma con un banale print non compare nulla .....
ho anceh provato a fare un semplice prog con l'ide .... ma anche qui' si connette (ho seguito i watchstop) ma rimane in attesa indefinita e non si genera ALCUN evento ......