View Full Version : TCP/IP - UDP connection & Mivascript
Claudiu
03-29-06, 08:37 PM
Ok Mivascript developers... let's see if there is an answer for this question:
- Is there any way that a Mivascript C library create a TCP/IP or UDP connection? I'm using python or php to do that... and I'm asking myself if a Mivascript library could give us more accessibility to the server resources... Am I wrong?
Another question.. for the MivaGuru outhere. Can someone give us more infos about creating Library. Is there any chance that we get a REAL API for that?
Thanks
Claudiu Bischoff
Mark Hughes
03-30-06, 02:57 AM
Hi Claudia,
Short answer: Yes. One can create a C library containing a custom function for handling TCP/IP connections.
I will try to obtain an example and/or instructions for you on how to go about creating such a function.
Mark
Claudiu
03-30-06, 05:15 AM
Hi Mark and thanks for your answer..
Of course, first, please, give some credit to my *** and let me be a man :D (my name is Claudiu).. and second .. a good example would be DAMN GOOOD!!!! We are a bunch of guys who try desperately to use ONLY Mivascript (no more mix with other languages) and creating libraries would help us for every task we have to do...
Also we really want to make some Mivascript Open Source projects, but it's difficult to make it if we cannot have more access to the server resources...
I see that the Miva Staff is monitoring the forum and that is great... If there is some MivaScript Core developers who love Miva Script as we do, it could be great to have some help for our Open Source Projects. When I look on the Sun Community and when I see all the support that Java Dev Staf is giving to the developers for creating new projects, man... I cry :( I still dream about such a community named Miva...
Best regards
Claudiu Bischoff
ILoveHostasaurus
03-30-06, 08:08 AM
Is there any way that a Mivascript C library create a TCP/IP or UDP connection?
UDP is a connectionless protocol. :)
Claudiu
03-30-06, 08:18 AM
Yep.. and I need a way to retrive the casting data only with mivascript .. :)
Mark Hughes
03-30-06, 06:35 PM
Of course, first, please, give some credit to my *** and let me be a man :D (my name is Claudiu)....
Oops. :o The difference a vowel makes.
benwalsh
03-31-06, 07:19 PM
Hi Mark,
I'm attempting something similar to Claudiu. Would you mind sending me whatever examples/instructions as well?
Much appreciated!
Ben
P.S. I for one like the new forum.
Mark Hughes
03-31-06, 08:50 PM
Here is a sample of source (excluding includes) for a library to introduce the capability of writing to the Apache error logs. Provided Empresa is configured to make use of the library, MIVA Script programs will be able to make use of the functions:
-print_stderr
-test_sleep
-test_port
// vi:set ts=4 sts=4 sw=4:
// $Id: file.cpp,v 1.20 2003/08/22 17:55:17 jwaters Exp $
/*
| Miva Virtual Machine interface sample.
|
| This file and the source codes contained herein are the property | of Miva Corporation. Use of this file is restricted to the specific | terms and conditions in the License Agreement associated with this | file. Distribution of this file or portions of this file for uses | not covered by the License Agreement is not allowed without a written | agreement signed by an officer of Miva Corporation.
|
| Copyright 1998-2003 Miva Corporation. All rights reserved.
| http://www.miva.com/
|
*/
#include "../api/mivapi.h"
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <unistd.h>
#include <semaphore.h>
extern "C"
{
MV_EL_FunctionParameter print_stderr_parameters[] = {
{ "source", 6, EPF_NORMAL },
};
void bi_print_stderr( mvProgram prog, mvVariableHash parameters, mvVariable returnvalue, void ** ) {
mvVariable source ;
const char *sourcedata ;
int sourcedata_length ;
int count ;
source = mvVariableHash_Index( parameters, 0 );
sourcedata = mvVariable_Value( source, &sourcedata_length );
count = fprintf( stderr , "%.*s\n" , sourcedata_length , sourcedata ) ;
mvVariable_SetValue_Integer( returnvalue, count );
}
MV_EL_FunctionParameter test_sleep_parameters[] = {
{ "seconds", 7, EPF_NORMAL },
};
void bi_test_sleep( mvProgram prog, mvVariableHash parameters, mvVariable returnvalue, void ** ) {
mvVariable source ;
int count ;
source = mvVariableHash_Index( parameters, 0 );
count = mvVariable_Value_Integer( source );
sleep( count ) ;
}
MV_EL_FunctionParameter test_port_parameters[] = {
{ "page", 4, EPF_NORMAL },
{ "result", 6, EPF_REFERENCE },
};
void bi_test_port( mvProgram prog, mvVariableHash parameters, mvVariable returnvalue, void ** ) {
mvNetworkConnection handle;
const char *uri;
int uri_length;
char buffer[ 1024 ];
int buffer_length;
int status = 1;
uri = mvVariable_Value( mvVariableHash_Index( parameters, 0 ), &uri_length );
// Note: mvNetwork_OpenURL would be a higher-level, friendlier way of doing this, with
// variables, methods, and all that good stuff.
handle = mvNetwork_Connect( prog, "localhost", 80 );
if ( handle == NULL )
{
status = 0;
}
if ( status )
{
buffer_length = snprintf( buffer, sizeof( buffer ), "GET /%.*s HTTP/1.0\r\n\r\n", uri_length, uri );
status = ( mvNetwork_Write( handle, buffer, buffer_length ) != -1 ) ; // write returns a length, or -1 on failure
}
if ( status )
{
buffer_length = mvNetwork_Read( handle, buffer, sizeof( buffer ), 3 );
status = mvVariable_SetValue( mvVariableHash_Index( parameters, 1 ), buffer, buffer_length );
}
mvVariable_SetValue_Integer( returnvalue, status ); }
/*
* Miva Function Table
*
* Defines the functions that Miva scripts can call from this shared object */
MV_EL_Function_List *miva_function_table() {
static MV_EL_Function exported_functions[] =
{
{ "print_stderr", 12, 1, print_stderr_parameters, bi_print_stderr } ,
{ "test_sleep", 10, 1, test_sleep_parameters, bi_test_sleep } ,
{ "test_port", 9, 2, test_port_parameters, bi_test_port } ,
{ 0 , 0 , 0, 0 , 0 }
};
static MV_EL_Function_List list = { MV_EL_FUNCTION_VERSION, exported_functions };
return &list;
}
}
Apologies to Claudiu for my gaffe.
Thanks to Ben for his encouraging remark.
Mark
Claudiu
04-03-06, 08:11 PM
Thanks very much Mark ;) . I'll take a look on it quick ...
PS: I was not offensed... I found it funny :D
Best regards,
Claudiu Bischoff
Claudiu
04-06-06, 12:47 AM
Hi, it's me again... I have studied all the stuff (and thanks again for your example). Now we have a small question.. Is there any way that we could get the MivAPI.lib compiled for debug? (not compiled for release) so we can debug a little?
Many thanks
Claudiu Bischoff
Mark Hughes
04-10-06, 06:46 PM
Hi Claudiu,
The release version is available here: http://smallbusiness.miva.com/products/compiler/
Are you looking for a MivAPI.lib with debug output specifically added?
Mark
Claudiu
04-10-06, 07:15 PM
Are you looking for a MivAPI.lib with debug output specifically added?
... yes.. that one :)
Thanks again!!
Claudiu Bischoff
Mark Hughes
04-10-06, 07:23 PM
A debug version of the compiler is not currently available. I will look into it.
Mark
Claudiu
04-10-06, 07:59 PM
I understand :o ... That would be a real help for us, but I'll wait to see if you find any solution for that :)
Thank you again. I really appreciate your involvement and help!
Claudiu Bischoff
vBulletin® v3.7.4, Copyright ©2000-2008, Jelsoft Enterprises Ltd.