isocket connection | developer.brewmp.com isocket connection | developer.brewmp.com

Developer

isocket connection

Forums:

we need to refresh our data coming from server,but we are not able to write it to da server second time without reopening da connection,wat could be da problem,
is it necessary to open da connection every time u write....

Hi Ashutosh,
I don't think that in your case there is a need to ReOpen the socket each time you want to refresh the data you are currently Reading/Writing from the server.
The api,
ISOCKET_Cancel(ISocket * pISocket, PFNNOTIFY pfn, void * pUser)
will suffice your purpose.
Hope it will work~~~~~~
SoftEast :eek:

Hi Ashutosh,
I don't think that in your case there is a need to ReOpen the socket each time you want to refresh the data you are currently Reading/Writing from the server.
The api,
ISOCKET_Cancel(ISocket * pISocket, PFNNOTIFY pfn, void * pUser)
will suffice your purpose.
Hope it will work~~~~~~
SoftEast :eek:

is it necessary to open da connection every time u write?
no u dont have to reopen the connection every time.
as for your problem are you sure that you store and use the same Isocket object and not creating a new one each time you send a new data.
second what error you got when you try to send data the second time
(you said that you open connection send command and finish then you send another command)
second if this didnt work insert the sockets part of the code we may able to help you with it .

is it necessary to open da connection every time u write?
no u dont have to reopen the connection every time.
as for your problem are you sure that you store and use the same Isocket object and not creating a new one each time you send a new data.
second what error you got when you try to send data the second time
(you said that you open connection send command and finish then you send another command)
second if this didnt work insert the sockets part of the code we may able to help you with it .

If you are waiting more than 30 seconds, you might look at the documentation for INETMGR_SetLinger().

If you are waiting more than 30 seconds, you might look at the documentation for INETMGR_SetLinger().

ok friends thanks for your reply,i got the idea how how to get things refreshed.
though still i am opening the connection again usiing set timer.
now i just want to clarify follwing query..
do u hav any idea wt should be the call flow for
1 user sending req for connection to server
2 server responds with field req for connection..say username n pass word
3 user provide it with username n pas..
4 now user is connected and can send n recieve messages.
now problem is if i again opens connection to write my data everytime ,i feel it will not be optimal.
can u tellme when i shoul open connection ,when i should close it ,wt r the things for which i should take care while reading n writting the data.
with regards
ashutosh

ok friends thanks for your reply,i got the idea how how to get things refreshed.
though still i am opening the connection again usiing set timer.
now i just want to clarify follwing query..
do u hav any idea wt should be the call flow for
1 user sending req for connection to server
2 server responds with field req for connection..say username n pass word
3 user provide it with username n pas..
4 now user is connected and can send n recieve messages.
now problem is if i again opens connection to write my data everytime ,i feel it will not be optimal.
can u tellme when i shoul open connection ,when i should close it ,wt r the things for which i should take care while reading n writting the data.
with regards
ashutosh

dear abd
we were not getting any data second time when we tried to read though we
r expecting image from server.
Ashutosh

dear abd
we were not getting any data second time when we tried to read though we
r expecting image from server.
Ashutosh

hi
when i work with sockets i usually make the client initiate all the connection and messages(or what i call them commands :) ) with the server
so the Flow will be :
1 user sending request for connection to server
2- server accept connection.
3-Client show login screen.(user enters the name and pass)
4-user Press login button.
5-the Client send login Command :
A-Client send a int with value for example 4 (where 4 is the number of command)
B-Client send user name as String
C-Client send pass as String
D-server got the data and process it .
6-the server respond with a value(for example 100 for correct user name and pass , 101 for non correct user and pass)
7-make sure that the server will keep the client session opened (the closing error might be a server side error.
8-remember to keep your ISocket object in a safe place all the time like in the main structure
8-as long as u keep your ISocket in a safe place and in the server the session alive you should be connected all the time
9- for the image ( create a new command and for example give it the number 5)
assume that this is ur application
simpleExample_HandleEvent(......)
{
case EVT_APP_START:
//init ur data
beforConnecting (pMe);
break;

void beforConnecting (simpleExample * pMe)
{
//1 user sending req for connection to server
ISOCKET_Connect(pISocket,IP,portNumber,afterConnec ting, (void*)pMe);
}
void afterConnecting (simpleExample * pMe, int nError)
{
//this function will be called once the socket finished connecting
//the only added thing that distinguish this function is that it must contain two variables the first is of the same type as the one defined in ISocket_Connect
//and the other is an integer defining the error returned
if(noError)
{
//send the Command number and the Strings
//calling login command
loginCommmand(pMe);

}
login(simpleExample * pMe)
{
//send an integer 4
ISOCKET_Write(....4,sendingUserName,...);//this will send 4 and upon finish call sendingUserName

sendingUserName(simpleExample * pMe)
{
//check for errors
ISOCKET_Write(...."ABD",sendingPassWord);

sendingPassWord(simpleExample * pMe)
{
//check for errors
ISOCKET_Write(...."****",gettingResponse);

gettingResponse (simpleExample * pMe)
{
//check for errors
ISOCKET_Read(....RESPOND,afterResponse);

afterResponse(simpleExample * pMe)
{
//check for errors
//if server send invalid handle error
//if server send correct use name and pass process it and then start send the image command using the same ISocket object.....

be careful when dealing with errors (since u might get WOULD_BLOCK) if so call ur function again and u must keep track of the data and how much u received and how much is left

hi
when i work with sockets i usually make the client initiate all the connection and messages(or what i call them commands :) ) with the server
so the Flow will be :
1 user sending request for connection to server
2- server accept connection.
3-Client show login screen.(user enters the name and pass)
4-user Press login button.
5-the Client send login Command :
A-Client send a int with value for example 4 (where 4 is the number of command)
B-Client send user name as String
C-Client send pass as String
D-server got the data and process it .
6-the server respond with a value(for example 100 for correct user name and pass , 101 for non correct user and pass)
7-make sure that the server will keep the client session opened (the closing error might be a server side error.
8-remember to keep your ISocket object in a safe place all the time like in the main structure
8-as long as u keep your ISocket in a safe place and in the server the session alive you should be connected all the time
9- for the image ( create a new command and for example give it the number 5)
assume that this is ur application
simpleExample_HandleEvent(......)
{
case EVT_APP_START:
//init ur data
beforConnecting (pMe);
break;

void beforConnecting (simpleExample * pMe)
{
//1 user sending req for connection to server
ISOCKET_Connect(pISocket,IP,portNumber,afterConnec ting, (void*)pMe);
}
void afterConnecting (simpleExample * pMe, int nError)
{
//this function will be called once the socket finished connecting
//the only added thing that distinguish this function is that it must contain two variables the first is of the same type as the one defined in ISocket_Connect
//and the other is an integer defining the error returned
if(noError)
{
//send the Command number and the Strings
//calling login command
loginCommmand(pMe);

}
login(simpleExample * pMe)
{
//send an integer 4
ISOCKET_Write(....4,sendingUserName,...);//this will send 4 and upon finish call sendingUserName

sendingUserName(simpleExample * pMe)
{
//check for errors
ISOCKET_Write(...."ABD",sendingPassWord);

sendingPassWord(simpleExample * pMe)
{
//check for errors
ISOCKET_Write(...."****",gettingResponse);

gettingResponse (simpleExample * pMe)
{
//check for errors
ISOCKET_Read(....RESPOND,afterResponse);

afterResponse(simpleExample * pMe)
{
//check for errors
//if server send invalid handle error
//if server send correct use name and pass process it and then start send the image command using the same ISocket object.....

be careful when dealing with errors (since u might get WOULD_BLOCK) if so call ur function again and u must keep track of the data and how much u received and how much is left

I am not sure what you are asking???
But, if I read you correctly, you want the second connection to not require the login again. If so, then the issue is with the server.
Usually what is done, is that after the login is successful, the server returns a session ID . You will need to cache this value and use it in the header of any subsequent requests that you send to the server.
But due to timeouts, you should be prepared to respond to a 401 or 407 HTTP response and login again.
Hope that helps.

I am not sure what you are asking???
But, if I read you correctly, you want the second connection to not require the login again. If so, then the issue is with the server.
Usually what is done, is that after the login is successful, the server returns a session ID . You will need to cache this value and use it in the header of any subsequent requests that you send to the server.
But due to timeouts, you should be prepared to respond to a 401 or 407 HTTP response and login again.
Hope that helps.

hi to all
i am really helped by both of above replies...
now i am able to send n recieve xml quieries to server.infact registration part is completed.
only big issue is i hav to generate random ID with every transaction.i used following code
int16 nrBits = 32;
int32 returnValue;
byte* rnd = new byte[nrBits/8];
GETRAND(rnd, nrBits/8);
returnValue = 0;
for(int16 i=0;i

hi to all
i am really helped by both of above replies...
now i am able to send n recieve xml quieries to server.infact registration part is completed.
only big issue is i hav to generate random ID with every transaction.i used following code
int16 nrBits = 32;
int32 returnValue;
byte* rnd = new byte[nrBits/8];
GETRAND(rnd, nrBits/8);
returnValue = 0;
for(int16 i=0;i

this code was done using C++
i think u need to change it to BREW C code as follow(the new will become MALLOC)
...
byte* rnd = (byte *)MALLOC(nrBits/8);
...
from the BREW API :
Quote:
GETRAND()
Description:
This function uses the random number generator on the device to fill an input buffer with an array of random values
Prototype:
void GetRand(byte * pDest, int nSize)
Parameters:
pDest Pointer to the destination buffer.
nSize Size in bytes of the buffer.
Return Value:
None

this code was done using C++
i think u need to change it to BREW C code as follow(the new will become MALLOC)
...
byte* rnd = (byte *)MALLOC(nrBits/8);
...
from the BREW API :
Quote:
GETRAND()
Description:
This function uses the random number generator on the device to fill an input buffer with an array of random values
Prototype:
void GetRand(byte * pDest, int nSize)
Parameters:
pDest Pointer to the destination buffer.
nSize Size in bytes of the buffer.
Return Value:
None

Hi abd_cie,
Regarding your comment ("this code was done using C++....... "):-
No it is not necessary to use MALLOC()... in that case. But yes, you will need to overload new, delete, new[] & delete[] operators as given below :
void* operator new(size_t size) { return MALLOC(size); }
void operator delete(void *ptr)
{ if(ptr)
{FREE(ptr);
ptr=NULL;} }
void* operator new[](size_t size) { return MALLOC(size); }
void operator delete[](void *ptr) {
FREE(ptr);
ptr=NULL;}
//after this overloading; indirectly MALLOC() will be invoked when 'new' is used.
Regards,
SoftEast

Hi abd_cie,
Regarding your comment ("this code was done using C++....... "):-
No it is not necessary to use MALLOC()... in that case. But yes, you will need to overload new, delete, new[] & delete[] operators as given below :
void* operator new(size_t size) { return MALLOC(size); }
void operator delete(void *ptr)
{ if(ptr)
{FREE(ptr);
ptr=NULL;} }
void* operator new[](size_t size) { return MALLOC(size); }
void operator delete[](void *ptr) {
FREE(ptr);
ptr=NULL;}
//after this overloading; indirectly MALLOC() will be invoked when 'new' is used.
Regards,
SoftEast

Softeast wrote:Hi abd_cie,
Regarding your comment ("this code was done using C++....... "):-
No it is not necessary to use MALLOC()... in that case. But yes, you will need to overload new, delete, new[] & delete[] operators as given below :
void* operator new(size_t size) { return MALLOC(size); }
void operator delete(void *ptr)
{ if(ptr)
{FREE(ptr);
ptr=NULL;} }
void* operator new[](size_t size) { return MALLOC(size); }
void operator delete[](void *ptr) {
FREE(ptr);
ptr=NULL;}
//after this overloading; indirectly MALLOC() will be invoked when 'new' is used.
Regards,
SoftEast
thanks
now we are able to generate random no,
but da problem is not able append it to a char,
as random no is of byte/integer,
and string is char its not appending
below is da code
unsigned char cmd1[]= "

Softeast wrote:Hi abd_cie,
Regarding your comment ("this code was done using C++....... "):-
No it is not necessary to use MALLOC()... in that case. But yes, you will need to overload new, delete, new[] & delete[] operators as given below :
void* operator new(size_t size) { return MALLOC(size); }
void operator delete(void *ptr)
{ if(ptr)
{FREE(ptr);
ptr=NULL;} }
void* operator new[](size_t size) { return MALLOC(size); }
void operator delete[](void *ptr) {
FREE(ptr);
ptr=NULL;}
//after this overloading; indirectly MALLOC() will be invoked when 'new' is used.
Regards,
SoftEast
thanks
now we are able to generate random no,
but da problem is not able append it to a char,
as random no is of byte/integer,
and string is char its not appending
below is da code
unsigned char cmd1[]= "

Hi mk.manju,
Anyways, I am surpised that you are using directly STRCAT() for appending String with a integer.
You must make these 2 params compatible with each other..
So, make integer variable a string... given is the code snipped to do that....
char cmd1[]= ";//rand is integer no. u want to append

else
;//no memory
now cmd1 contains the string with random no. concatenated...
:) :o
SoftEast

Hi mk.manju,
Anyways, I am surpised that you are using directly STRCAT() for appending String with a integer.
You must make these 2 params compatible with each other..
So, make integer variable a string... given is the code snipped to do that....
char cmd1[]= ";//rand is integer no. u want to append

else
;//no memory
now cmd1 contains the string with random no. concatenated...
:) :o
SoftEast

Softeast wrote:Hi mk.manju,
Anyways, I am surpised that you are using directly STRCAT() for appending String with a integer.
You must make these 2 params compatible with each other..
So, make integer variable a string... given is the code snipped to do that....
char cmd1[]= ";//rand is integer no. u want to append

else
;//no memory
now cmd1 contains the string with random no. concatenated...
:) :o
SoftEast
thanks
it works fine when i write to file not at serverside
int random_num = 9999;random no container//for da moment static im using
char* cmd1 = (char*) MALLOC(500);
unsigned char cmd111[]= "' type='set'>";
char pszTemp[10];//contains username retrived frm text box
unsigned char cmd2[]="neos";
char pszTemps[10];password holder
unsigned char cmd8[]="";
SPRINTF(cmd1, "

Softeast wrote:Hi mk.manju,
Anyways, I am surpised that you are using directly STRCAT() for appending String with a integer.
You must make these 2 params compatible with each other..
So, make integer variable a string... given is the code snipped to do that....
char cmd1[]= ";//rand is integer no. u want to append

else
;//no memory
now cmd1 contains the string with random no. concatenated...
:) :o
SoftEast
thanks
it works fine when i write to file not at serverside
int random_num = 9999;random no container//for da moment static im using
char* cmd1 = (char*) MALLOC(500);
unsigned char cmd111[]= "' type='set'>";
char pszTemp[10];//contains username retrived frm text box
unsigned char cmd2[]="neos";
char pszTemps[10];password holder
unsigned char cmd8[]="";
SPRINTF(cmd1, "

HI Manju,
1. I missed one line from my code snippet.. pl observe below lines:
char* cmd1 = (char*) MALLOC(50);
//
if(cmd1)
{
//initialise the buffer first; This is causing Garbage in your case, I think
MEMSET(cmd1,0,50);
SPRINTF(cmd1, ";//rand is integer no. u want to append

else
;//no memory
2. Also, check your buffer size (i.e.500) is sufficient or not to accomodate all the STRCATs
HOpe this will work...
SoftEast

HI Manju,
1. I missed one line from my code snippet.. pl observe below lines:
char* cmd1 = (char*) MALLOC(50);
//
if(cmd1)
{
//initialise the buffer first; This is causing Garbage in your case, I think
MEMSET(cmd1,0,50);
SPRINTF(cmd1, ";//rand is integer no. u want to append

else
;//no memory
2. Also, check your buffer size (i.e.500) is sufficient or not to accomodate all the STRCATs
HOpe this will work...
SoftEast

Softeast wrote:HI Manju,
1. I missed one line from my code snippet.. pl observe below lines:
char* cmd1 = (char*) MALLOC(50);
//
if(cmd1)
{
//initialise the buffer first; This is causing Garbage in your case, I think
MEMSET(cmd1,0,50);
SPRINTF(cmd1, ";//rand is integer no. u want to append

else
;//no memory
2. Also, check your buffer size (i.e.500) is sufficient or not to accomodate all the STRCATs
HOpe this will work...
SoftEast
HI
I TRIED WITH ABOVE CODE BUT STILL SAME PROBLEM, I FEEL DA WAY I HAVE DECLARED DA STRINGS IN ABOVE CODE IS NOT PROPER, HOW TO DYNAMICALL ALLOCATE MEMORY FOR ABOVE STRING, AND LET THET TRING DATATYPE BE UNSIGNED CHAR OR SOMETHING ELSE, so wat to be done further its working for me if i use static id with da string fine,but as per req i should append random no for each transaction.....

Softeast wrote:HI Manju,
1. I missed one line from my code snippet.. pl observe below lines:
char* cmd1 = (char*) MALLOC(50);
//
if(cmd1)
{
//initialise the buffer first; This is causing Garbage in your case, I think
MEMSET(cmd1,0,50);
SPRINTF(cmd1, ";//rand is integer no. u want to append

else
;//no memory
2. Also, check your buffer size (i.e.500) is sufficient or not to accomodate all the STRCATs
HOpe this will work...
SoftEast
HI
I TRIED WITH ABOVE CODE BUT STILL SAME PROBLEM, I FEEL DA WAY I HAVE DECLARED DA STRINGS IN ABOVE CODE IS NOT PROPER, HOW TO DYNAMICALL ALLOCATE MEMORY FOR ABOVE STRING, AND LET THET TRING DATATYPE BE UNSIGNED CHAR OR SOMETHING ELSE, so wat to be done further its working for me if i use static id with da string fine,but as per req i should append random no for each transaction.....

Hi Manju,
I think the way you are using Unsighned Char string is not proper,
like
unsigned char cmd111[].....
this is nothing but a byte array .. so it may show unexpected behaviour in case of strings ..
so I think
1. If possible do not use "unsigned char*" if can be done with char*
2. If it is required in your code to use those "unsigned char*", then you should use MEMCPY() to copy those buffers [STRCAT/STRCPY won't work sometimes depending upon your string, like if a byte =0 exist in your byte array then it stops copying/concatenating before end of the string !!! Also dest str will not be appended with '\0' so your string is garbage now].
and after MEMCPYing; append the destination string with EOS(End of String) character '\0' if necessary.
Hopw this will work.
SoftEast :) :o

Hi Manju,
I think the way you are using Unsighned Char string is not proper,
like
unsigned char cmd111[].....
this is nothing but a byte array .. so it may show unexpected behaviour in case of strings ..
so I think
1. If possible do not use "unsigned char*" if can be done with char*
2. If it is required in your code to use those "unsigned char*", then you should use MEMCPY() to copy those buffers [STRCAT/STRCPY won't work sometimes depending upon your string, like if a byte =0 exist in your byte array then it stops copying/concatenating before end of the string !!! Also dest str will not be appended with '\0' so your string is garbage now].
and after MEMCPYing; append the destination string with EOS(End of String) character '\0' if necessary.
Hopw this will work.
SoftEast :) :o

To all:
hello!:D
I'am a beginner of BREW.i'm try to write a chatting app just like ICQ/QQ.while i use the isocket interface,there are some problems~~
using tcp,i don't want to connect to the the servers online,but just to my owm computer.... well,Brew app can not act as a server..
What should i do?
change my tcp to udp?my god!
can anyone give me an answer....
thanks~~! :o

To all:
hello!:D
I'am a beginner of BREW.i'm try to write a chatting app just like ICQ/QQ.while i use the isocket interface,there are some problems~~
using tcp,i don't want to connect to the the servers online,but just to my owm computer.... well,Brew app can not act as a server..
What should i do?
change my tcp to udp?my god!
can anyone give me an answer....
thanks~~! :o

my problem is im writing da data from server to xml file and giving this file to parser,
and parser parses da data and puts it on da screen,but once again when i recieve da data from server im not able to create new xml file for it as parser is using tat file to print data on screen,so how to release da parser from using file after displaying data from file
im using parser from developer extranet
IXMLParser* pXmlParser;
this pointer im using............
waiting for reply
regards
manju

my problem is im writing da data from server to xml file and giving this file to parser,
and parser parses da data and puts it on da screen,but once again when i recieve da data from server im not able to create new xml file for it as parser is using tat file to print data on screen,so how to release da parser from using file after displaying data from file
im using parser from developer extranet
IXMLParser* pXmlParser;
this pointer im using............
waiting for reply
regards
manju

mk.manju wrote:my problem is im writing da data from server to xml file and giving this file to parser,
and parser parses da data and puts it on da screen,but once again when i recieve da data from server im not able to create new xml file for it as parser is using tat file to print data on screen,so how to release da parser from using file after displaying data from file
im using parser from developer extranet
IXMLParser* pXmlParser;
this pointer im using............
waiting for reply
regards
manju
Although you are using XML data which is stored in file; you should have Released the IFile obj once you get the data into your working buffer. If not, It should be your way of implementation because it isn't a good practice to put the file in blocked mode("reading" state), while you are displaying the file's data. The correct approach should be- 1)Read the IFile data, 2)store them temporarily on heap 3) Release all IFile obj and unblock the file for other operations (Read/Write) and 4) display the data from heap (not from file!!!!).
~~~~~~~
SoftEast
~~~~~~~

mk.manju wrote:my problem is im writing da data from server to xml file and giving this file to parser,
and parser parses da data and puts it on da screen,but once again when i recieve da data from server im not able to create new xml file for it as parser is using tat file to print data on screen,so how to release da parser from using file after displaying data from file
im using parser from developer extranet
IXMLParser* pXmlParser;
this pointer im using............
waiting for reply
regards
manju
Although you are using XML data which is stored in file; you should have Released the IFile obj once you get the data into your working buffer. If not, It should be your way of implementation because it isn't a good practice to put the file in blocked mode("reading" state), while you are displaying the file's data. The correct approach should be- 1)Read the IFile data, 2)store them temporarily on heap 3) Release all IFile obj and unblock the file for other operations (Read/Write) and 4) display the data from heap (not from file!!!!).
~~~~~~~
SoftEast
~~~~~~~

Thanks we were able to solve above problem from manju.
bt the message we r getting hav lot of boxes(these r actually whitespaces not in message bt before n after ....tags).since we r using raxion parser ..is there any supprot in it to remove white spaces.

Thanks we were able to solve above problem from manju.
bt the message we r getting hav lot of boxes(these r actually whitespaces not in message bt before n after ....tags).since we r using raxion parser ..is there any supprot in it to remove white spaces.

byte BAR_RS[]={30};
byte BAR_US[]={31};
byte BAR_EOH[]={31,31};
these are the delimiters that my java server is using between different statements.
the way i declared in my brew client is
byte BAR_RS[]={30,0};
byte BAR_US[]={31,0};
byte BAR_EOH[]={31,31,0};
first two are working gud enough but theres problem in third one ,can u plz suggest me the better way.
i feel statements like STRLEN(BAR_US) or
SNPRINTF(pMe->request,len,"%s%s%s%s%d%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",req,
BAR_US,req1,
BAR_US,pMe->size_image,BAR_EOH,req2,
BAR_US,req3,pMe->usernames,req4,
BAR_US,req5,pMe->pass,
BAR_US,req6,filename,
BAR_US,req8,BAR_US,BAR_RS//,pMe->image_buffer
);
should not give any problem..wt u say, req1.... all are "char *".
regards
Ashutosh Sharma

byte BAR_RS[]={30};
byte BAR_US[]={31};
byte BAR_EOH[]={31,31};
these are the delimiters that my java server is using between different statements.
the way i declared in my brew client is
byte BAR_RS[]={30,0};
byte BAR_US[]={31,0};
byte BAR_EOH[]={31,31,0};
first two are working gud enough but theres problem in third one ,can u plz suggest me the better way.
i feel statements like STRLEN(BAR_US) or
SNPRINTF(pMe->request,len,"%s%s%s%s%d%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",req,
BAR_US,req1,
BAR_US,pMe->size_image,BAR_EOH,req2,
BAR_US,req3,pMe->usernames,req4,
BAR_US,req5,pMe->pass,
BAR_US,req6,filename,
BAR_US,req8,BAR_US,BAR_RS//,pMe->image_buffer
);
should not give any problem..wt u say, req1.... all are "char *".
regards
Ashutosh Sharma