Prev: Having problems with ReportPro after upgrading VO2.8 to SP2
Next: Displaying JPG in a BBrowser cell - sample code please
From: Tom Szabo on 22 Nov 2008 11:24 Hi Alessandro, Thanks very much Tom "Alessandro Antonangeli" <alcati(a)alcati.RemoveThis.com> wrote in message news:gg94gk$opg$1(a)aioe.org... > > What you sent me is all really good info, but my primary problem is that I > > don't know how to start with making a connection. > > Well, you have a lot of job then!!! > > I use mainly the VO class cSocket: I sublcassed it because I need > asyncronous connection. I did find in this newgroup some code for making it: > look for WSAAsyncSelect > I put here the code I use to make the client connect to the server: this is > only part of the code, but it may help you. Basically with WSAAsyncSelect > you can have an event dispatched to a class. And this was what i needed, > otherwise you must keep on listening to the port > > First of all look to CAVO cSocket help and example. > Mainly to send and receive data I use SendRawText and GetRawText: if you > look to them in the help file, you will find some good example, may be > enought for you > > Sorry, but comment and name are in Italian: NumPorta is the port number > (5999 of the previous post), NomeHost is the name or the IP address of your > asterisk machine > The LG(.....) function just make a log file/output: you can ignore them > MioSocket is a subclass of cSocket > > -- > Ciao > Alessandro > > METHOD AscoltaClient(NumPorta AS DWORD,NomeHost AS STRING) AS DWORD CLASS > TCPGestione > > LOCAL oClientSocket AS MioSocket > > LOCAL nSocket AS DWORD > > LOCAL IndirizzoIP AS STRING > > oClientSocket:=MioSocket{SOCK_STREAM} > > nSocket:=oClientSocket:NumSocket > > IF Empty(NomeHost) > > NomeHost:=HostName() > > ENDIF > > IndirizzoIP:=GetIPAddress(NomeHost) > > Lg("Connessione di",nSocket,"a IndirizzoIP,NumPorta",IndirizzoIP,NumPorta) > > IF !oClientSocket:connect(IndirizzoIP,NumPorta) > > /*SSTAT_UNINITIALIZED > > SSTAT_DISCONNECTED > > SSTAT_CONNECTING > > SSTAT_LISTENING > > SSTAT_DISCONNECTING > > SSTAT_CONNECTED > > SSTAT_ERRORSTATE > > SSTAT_TIMEDOUT > > */ > > Lg("Errore nella > connessione",IndirizzoIP,NumPorta,oClientSocket:ErrorMsg,oClientSocket:Statu s) > > oClientSocket:Close() > > oClientSocket:=NULL_OBJECT > > RETURN INVALID_SOCKET > > ENDIF > > IF > WSAAsyncSelect(nSocket,SELF:hwSWHandle,SELF:dwNotificationMessage,FD_READ+FD _WRITE+FD_CLOSE)==0 > > Lg("Socket accepting IN non-blocking mode") > > ELSE > > Lg("ERRORE Socket NON accepting IN non-blocking mode") > > oClientSocket:=NULL_OBJECT > > nSocket:=INVALID_SOCKET > > ENDIF > > IF oClientSocket=NULL_OBJECT > > IF shutdown(nSocket,SD_BOTH)==0 > > closesocket(nSocket) > > ENDIF > > nSocket:=INVALID_SOCKET > > ELSE > > oClientSocket:AssegnaGestore(SELF) > > AAdd(aSockets,oClientSocket) > > ENDIF > > Lg("Client in ascolto",nSocket,INVALID_SOCKET) > > Lg(oClientSocket:ErrorMsg) > > RETURN nSocket > >
From: Tom Szabo on 30 Nov 2008 03:25 Hi John, Thanks for the intention, I am after Socket type connection. Regards, Tom "John Martens" <adsl672100(a)tiscali.nl> wrote in message news:4927ffbf$0$24411$5fc3050(a)news.tiscali.nl... > Tom, > > You should use the cHttp class of VO. This is a basic example how to get a > file: > > oHttp := CHttp{"Asterisk connection"} > cHttpInhoud := oHttp:GetDocumentByURL("www.server.com\Folder\Mydoc.htm") > > Norbert Kolb's methdo for getting data from a from shows some more oof > cHttp: > > Cheers, > John > > > > > METHOD GetDocumentByForm(cIP, cDocument, cData, cHeaders) CLASS cHttp > *************************************** > // First the InternetOpen function is called to initialize the > // remaining functions. Then the InternetConnect function is called > // to identify the type of service being requested. This is necessary > // as the same set of functions can be used to interact with a number > // of different servers. > *************************************** > > LOCAL lResult AS LOGIC > LOCAL cPostData AS STRING > LOCAL nPostDataLen AS DWORD > LOCAL cRet AS STRING > > Default(@cIP, NULL_STRING) > Default(@cDocument, NULL_STRING) > Default(@cData, NULL_STRING) > cRet := NULL_STRING > > // Open the connection > IF SELF:hSession == NULL_PTR > SELF:hSession := InternetOpen(String2Psz(SELF:cAgent),; > INTERNET_OPEN_TYPE_PRECONFIG,; > NULL_PTR,; > NULL_PTR,; > 0 ) // INTERNET_FLAG_SECURE ipv 0 om https te gebruiken > ENDIF > > IF SELF:hSession <> NULL_PTR > // Identify the type OF service that IS being accessed > IF SELF:hConnect == NULL_PTR .OR. SELF:cHostAddress <> cIP > SELF:cHostAddress := cIP > SELF:hConnect := InternetConnect(SELF:hSession, ; > String2Psz(SELF:cHostAddress), ; > INTERNET_DEFAULT_HTTP_PORT, ; > NULL_PSZ, ; > NULL_PSZ, ; > INTERNET_SERVICE_HTTP, ; > 0, ; > 0) > ENDIF > > // > // Give computer some time (otherwise app could freeze) > ApplicationExec(EXECWHILEEVENT) > > IF SELF:hConnect <> NULL_PTR > // Once we've identified the service, we need to indicate the > // page to which the data will be posted. In this example, it will > // be "/getorpost.php" > SELF:hRequest := HttpOpenRequest(SELF:hConnect, ; > String2Psz("POST"), ; > String2Psz(cDocument), ; > String2Psz("HTTP/1.0"), ; > NULL_PSZ, ; > 0, ; > INTERNET_FLAG_RELOAD, ; > 0) > > // We need to add a header to notify the web server that the > // incoming data is form encoded and then send the request. > Default(@cHeaders, "Content-Type: application/x-www-form-urlencoded" + > CrLf) > lResult := HttpAddRequestHeaders(SELF:hRequest, ; > cHeaders, SLen(cHeaders), HTTP_ADDREQ_FLAG_ADD) > > // > // Give computer some time (otherwise app could freeze) > ApplicationExec(EXECWHILEEVENT) > > cPostData := cData > nPostDataLen := SLen(cPostData) > lResult := HttpSendRequest(SELF:hRequest, ; > NULL_PSZ, ; > 0, ; > PTR(_CAST, cPostData), ; > nPostDataLen) > > IF lResult > // Finally, we need to collect our reward for all this effort > cRet := SELF:GetResponse() > SELF:CloseRequest() > //ToonMelding('VRT-Antwoord op Http request',cRet) > ELSE cRet := 'FORM_ERROR: Request niet juist verzonden' > ENDIF > ELSE > cRet := 'FORM_ERROR: Connect niet juist gemaakt' > ENDIF > ELSE > cRet := 'FORM_ERROR: Sessie niet juist open' > ENDIF > RETURN cRet > > > > Tom Szabo schreef: >> Hi Alessandro, >> >> What you sent me is all really good info, but my primary problem is that >> I >> don't know how to start with making a connection. >> >> You mentioned that there are some examples in the VO Samples. Could you >> please point me ouy or give me more directions? >> >> Thanks very much for your help, I really do appreciate. >> >> TIA, >> >> Tom >> >> "Alessandro Antonangeli" <alcati(a)alcati.RemoveThis.com> wrote in message >> news:gg8l6s$vr1$1(a)aioe.org... >>> Hi Tom >>> Here are some hints: >>> First yo should be able to make a TCP connection (you can find examples >>> in >>> this NG and in CAVO sample) >>> You need a client connection to the Asterisk server >>> You must enable Asterisk to accept order trought TCP IP: see >>> /etc/asterisk/manager.conf >>> This an example >>> >>> [general] >>> enabled = yes >>> port = 5999 >>> bindaddr = 0.0.0.0 >>> ;displayconnects = yes >>> >>> [yyyyy] >>> secret=xxxxx >>> deny=0.0.0.0/0.0.0.0 >>> permit=127.0.0.1/255.255.255.255 >>> permit=192.168.1.1/255.255.255.0 >>> read = system,call,log,verbose,command,agent,user >>> write = system,call,log,verbose,command,agent,user >>> >>> Your CAVO application must connect to the IP address of your asterisk >> server >>> trougth the port you will specify in general (5999 in this example) >>> Than your application must login: this is an example >>> >>> oSocketCentralino:oMioSocket:cAltriDati:="Action: Login"+CrLf >>> oSocketCentralino:oMioSocket:cAltriDati+="ActionID: >>> AStringYouPrefer"+CrLf >>> oSocketCentralino:oMioSocket:cAltriDati+="Username: yyyyy"+CrLf >>> oSocketCentralino:oMioSocket:cAltriDati+="Secret: xxxxx"+CrLf >>> oSocketCentralino:oMioSocket:cAltriDati+="Events: On"+CrLf >>> >>> Please notice that username is the same than the section name [yyyyy] >>> and >>> the password is the one specified in secret >>> After that, it depends on what you need: for example to make a call >>> >>> oSocketCentralino:oMioSocket:cAltriDati:="Action: Originate"+CrLf >>> //NumDaChiamare is the phone number to call >>> IF Left(NumDaChiamare,1)$PrefissiValidi//for outgoing call >>> oSocketCentralino:oMioSocket:cAltriDati+="Channel: >>> zap/g1/"+NumDaChiamare+CrLf >>> ELSE //internal numbers >>> oSocketCentralino:oMioSocket:cAltriDati+="Channel: >>> SIP/"+NumDaChiamare+CrLf >>> ENDIF >>> oSocketCentralino:oMioSocket:cAltriDati+="Context: default"+CrLf >>> oSocketCentralino:oMioSocket:cAltriDati+="Exten: "+NumInterno+CrLf >>> oSocketCentralino:oMioSocket:cAltriDati+="Priority: 1"+CrLf >>> oSocketCentralino:oMioSocket:cAltriDati+="Callerid: >>> "+TelefonateInCorso[NumeroChiamateInCorso][4]+CrLf >>> oSocketCentralino:oMioSocket:cAltriDati+="Timeout: >>> "+Str(TempoDiAttesa,-1)+"000"+CrLf >>> oSocketCentralino:oMioSocket:cAltriDati+="Async: yes"+CrLf >>> >>> With this isctructions you tell asterisk to place a call to >>> NumDaChiamare >>> and when someone answer to pass the comunication to the internal >> NumInterno. >>> If the called party wont answer in TempoDiAttesa seconds, the call will >>> drop. >>> Note that with Async: yes, asterisk will be ready to place others call, >> with >>> Async: no you will have to wait for the asterisk answer. >>> The link you posted is the right way were to find information >>> Remember to send an empty line with a CrLf in order to instruct >>> Asterisk >>> your command is finished and to process it >>> HTH >>> >>> -- >>> Ciao >>> Alessandro >>> >>> "Tom Szabo" <tom(a)intersoft.net.au> ha scritto nel messaggio >>> news:49272f49$1(a)dnews.tpgi.com.au... >>>> Hi, >>>> >>>> I would like to connect from a VO app to an Asterisk system, but not >> sure >>>> how to go about it. >>>> >>>> http://www.voip-info.org/wiki/view/Asterisk+manager+API >>>> >>>> Any help would be greatly appreciated >>>> >>>> TIA, >>>> >>>> Tom >>>> >>>> >>> >>
From: Tom Szabo on 30 Nov 2008 03:27
Hi Alessandro, Thanks for all the help, I have the basic thing going. Looking back, without your stuff I would have no chance to get it going Thanks again, Tom "Alessandro Antonangeli" <alcati(a)alcati.RemoveThis.com> wrote in message news:gg94gk$opg$1(a)aioe.org... >> What you sent me is all really good info, but my primary problem is that >> I >> don't know how to start with making a connection. > > Well, you have a lot of job then!!! > > I use mainly the VO class cSocket: I sublcassed it because I need > asyncronous connection. I did find in this newgroup some code for making > it: look for WSAAsyncSelect > I put here the code I use to make the client connect to the server: this > is only part of the code, but it may help you. Basically with > WSAAsyncSelect you can have an event dispatched to a class. And this was > what i needed, otherwise you must keep on listening to the port > > First of all look to CAVO cSocket help and example. > Mainly to send and receive data I use SendRawText and GetRawText: if you > look to them in the help file, you will find some good example, may be > enought for you > > Sorry, but comment and name are in Italian: NumPorta is the port number > (5999 of the previous post), NomeHost is the name or the IP address of > your asterisk machine > The LG(.....) function just make a log file/output: you can ignore them > MioSocket is a subclass of cSocket > > -- > Ciao > Alessandro > > METHOD AscoltaClient(NumPorta AS DWORD,NomeHost AS STRING) AS DWORD CLASS > TCPGestione > > LOCAL oClientSocket AS MioSocket > > LOCAL nSocket AS DWORD > > LOCAL IndirizzoIP AS STRING > > oClientSocket:=MioSocket{SOCK_STREAM} > > nSocket:=oClientSocket:NumSocket > > IF Empty(NomeHost) > > NomeHost:=HostName() > > ENDIF > > IndirizzoIP:=GetIPAddress(NomeHost) > > Lg("Connessione di",nSocket,"a IndirizzoIP,NumPorta",IndirizzoIP,NumPorta) > > IF !oClientSocket:connect(IndirizzoIP,NumPorta) > > /*SSTAT_UNINITIALIZED > > SSTAT_DISCONNECTED > > SSTAT_CONNECTING > > SSTAT_LISTENING > > SSTAT_DISCONNECTING > > SSTAT_CONNECTED > > SSTAT_ERRORSTATE > > SSTAT_TIMEDOUT > > */ > > Lg("Errore nella > connessione",IndirizzoIP,NumPorta,oClientSocket:ErrorMsg,oClientSocket:Status) > > oClientSocket:Close() > > oClientSocket:=NULL_OBJECT > > RETURN INVALID_SOCKET > > ENDIF > > IF > WSAAsyncSelect(nSocket,SELF:hwSWHandle,SELF:dwNotificationMessage,FD_READ+FD_WRITE+FD_CLOSE)==0 > > Lg("Socket accepting IN non-blocking mode") > > ELSE > > Lg("ERRORE Socket NON accepting IN non-blocking mode") > > oClientSocket:=NULL_OBJECT > > nSocket:=INVALID_SOCKET > > ENDIF > > IF oClientSocket=NULL_OBJECT > > IF shutdown(nSocket,SD_BOTH)==0 > > closesocket(nSocket) > > ENDIF > > nSocket:=INVALID_SOCKET > > ELSE > > oClientSocket:AssegnaGestore(SELF) > > AAdd(aSockets,oClientSocket) > > ENDIF > > Lg("Client in ascolto",nSocket,INVALID_SOCKET) > > Lg(oClientSocket:ErrorMsg) > > RETURN nSocket > > |