PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

request sending

Hi,
I want to see how the socket is being formed and how is the connection is being set(like it happens in C Socket programming). I mean first the server waits for a connection and when a client wants a connection, the connection is set. Then the client sends a request and the server implements that request.

How to implement these sequence of steps in Edge. I already wrote a sample code in C in the topic "TCP Protocols" . I followed all the steps suggested by you and the program is compiling and linking well. But when I run the executable, simply a window appears with black screen. Can you suggest a way to display messages at each step and a way to know whether the connection has been set??

Also please tell me how to send requests from client to server like, for example client may send a string and ask the server to print it (similar to the C program that i pasted in topic "TCP Protocols"). Can you help me how to implement these steps in Edge both for Windows desktop and Symbian???

Hoping for a reply soon.

Thank you
coolkc
Hi Coolkc,

If a client request a connection with the server, he's added automatically through the ENET_ADDCLIENT event. The buffer will contain a text string with the IP-address of the client (cast it to char *).

To test the connection state we recommend checking against these messages:
Code:

ENET_SERVERFOUND //Connected to server
ENET_RUNNINGSERVER //Server is listening
ENET_ADDCLIENT //A client is added
ENET_CLOSEDSOCKET //The socket is closed
Hi,

I will show both the codes of client and server. Check them and see if there are any errors.

This is the code of the client :

Code:
bool ClassMain::Connect(bool usebluetooth)
{
if (usebluetooth)
{
if (ecd.net[0]->Init(ECONN_BLUETOOTH, this) == E_OK)
{
if (!ecd.net[0]->SearchHost("00:00:54:1F:8D:24", 4))
return(false);
}
else
return(false);
}
else
{
if(ecd.net[0]->Init(ECONN_SOCKET, this) == E_OK)
{
if(!ecd.net[0]->SearchHost("127.0.0.1", 4000))
return(false);
}
else
return(false);
}
return(true);
}

void ClassMain::OnNetMessage(unsigned char connection, long id, long msg, long bufsize, unsigned char *buffer)
{
switch(msg)
{
case ENET_SERVERFOUND:
//server is found
break;
case ENET_RUNNINGSERVER:
//the server is running
break;
}
}


This is the code of the server:

Code:
bool ClassMain::Connect(bool usebluetooth)
{
if (usebluetooth)
{
if (ecd.net[0]->Init(ECONN_BLUETOOTH, this) == E_OK)
{
if (!ecd.net[0]->SearchHost("NULL", 0))
return(false);
}
else
return(false);
}
else
{
if(ecd.net[0]->Init(ECONN_SOCKET, this) == E_OK)
{
if(!ecd.net[0]->SearchHost("NULL", 4000))
return(false);
}
else
return(false);
}
return(true);
}

void ClassMain::OnNetMessage(unsigned char connection, long id, long msg, long bufsize, unsigned char *buffer)
{
switch(msg)
{
case ENET_ADDCLIENT:
//client has been added
break;
case ENET_CLOSEDSOCKET:
//closed connection
break;
}
}


See these codes and please tell me what is the output that is expected. I am running them for windows desktop verison and i am just getting two windows with black screens. So i am not able to understand whether the programs are working well.
Please guide me stepwise with all the steps and suggest all changes to be made so that i can know that the connection has been set correctly and requests can be sent.In the codes "127.0.0.1" is referring to localhost.

Hoping to get a reply soon.

Thanking you,
coolkc
Hi Coolkc,

First I recommend checking the return value of your Connect() function (does it return true or false?). Move ENET_RUNNINGSERVER to your server code (instead of your client code).

When these events happen, use ClassEConsole :: MsgWindow() to show a message box. Do you get any events? If not, it could also be a problem with connecting to localhost. Try connecting to a website instead.
Hi,

Thank you very much for the reply. Now I have a running server and client applications. I am trying to implement basic fucntions now, like the client requests for a string and the server sends the string which is received by the client. If I have any doubts in this aspect I will post the problem.

Thank you,
coolkc
Hi,

I am trying to use the Function ShowMsg so that I can get the messages in the console window. But I am getting the following error:

ClassEConsole::ShowMsg' : illegal call of non-static member function
c:\projects\edge\include\econsole.h(29) : see declaration of 'ShowMsg'

Can you tell me how to remove this error? When I use MsgWindow, I did not get any such errors.

Thanking you,
coolkc
Hi Coolkc,

The ShowMsg function can't be used as a static function call (like ClassEConsole::MsgWindow). You need to call it from the ECD structure:

Code:

ecd.console->ShowMsg("message");


Calling a static function of a class means that you can call it without creating an instance of the class (using the "::" symbol). It depends on the function if this is possible.
Hi,

Thank you for the reply.

There is one 3ds model by name edgelogo in this server:
http://130.192.163.84:8080/edgelib/edgelogo.3ds

and I want to download this model from that server into my PC whose IP is 130.192.163.89

How to download this model from that server into my PC (which is the client)?? First the client should request for that model and then the server should send that model to that client. How to make such requests??

I am trying to use this command:
display->CreateSurface(&edgelogo;, "http://130.192.163.84:8080/edgelib/edgelogo.3ds", -3)

But I am not knowing how to specify the memsize and I am also not sure whether we can specify the mem pointer like the way I did. Can you please help me with this??

Hoping to get a reply soon.

Thank you
coolkc
Hi Coolkc,

Unfortunately, you can't specify an URL to the CreateSurface() function. You need to download it manually. We also recommend saving it on the device after downloading to save bandwidth.

To download a file using TCP/IP you can call ClassEConnect :: SendHTTPGet() with your URL as a parameter. After connecting to the server you should get ENET_RECEIVEDATA events with the file data. Use EHTTPStack to receive the data. More information on EHTTPStack is available here: http://www.edgelib.com/index.php?node=282
Hi,

Thank you for the reply. I have one more doubt. In the tutorial on HTTPRequest, the http link was something like this
www.test.com/testpage.php?ac=info

so the line
Code:
if (stack.GetResponseInfo(&info;))


was executed without any error.
But in my case the URL is something like this

http://130.192.5.71:8080/edgelib/edgelogo.3ds

The 3ds file is edgelogo.3ds. So how can I change the GetResponseInfo part of the code so that i can download the file into the stack (byte stream)??

Code:
ERESULT ClassMain::OnInit(EINSTANCE instance)
{
if(ecd.net[0]->Init(ECONN_SOCKET, this) == E_OK)
{
ClassEConsole::MsgWindow("Socket formed");
ecd.net[0]->SendHTTPGet("http://130.192.5.71:8080/edgelib/edgelogo.3ds");
ClassEConsole::MsgWindow("Server formed");
stack.Alloc(32768);
ClassEConsole::MsgWindow("test");
return(true);
}
else
{
ClassEConsole::MsgWindow("Socket not formed");
return(false);
}
}


void ClassMain::OnNetMessage(unsigned char connection, long id, long msg, long bufsize, unsigned char *buffer)
{
if (msg == ENET_SERVERFOUND)
{
ClassEConsole::MsgWindow("hi");
//The client has been connected
}

if (msg == ENET_RECEIVEDATA)
{
stack.Push(buffer, bufsize);
}

if(msg == ENET_CLOSEDSOCKET)
{
if (stack.GetResponseInfo(&info;))
{
if(stack.BodySize() == 0)
{
unsigned char *bodydata = NULL;
unsigned long bodydatasize;
bodydata = (unsigned char *)ClassEMemory::Alloc(stack.BodySize());

if (bodydata != NULL)
{
stack.GetBody(bodydata, bodydatasize);
ClassEMemory::DeAlloc(bodydata);
}
}
//}
stack.Clear();
}


I tried this code but the argument of GetResponseInfo must be a pointer to the information desired. I am not able to understand what should i pass as the argument. Can you please help me with this???

Thank you
coolkc
Hi Coolkc,

You need to create a variable to hold the response information, like this:

Code:

EHTTPRESPONSE_INFO info;
stack.GetResponseInfo(&info;);


This info structure contains information about the HTTP message, we recommend checking info.concentlength to see if it matches the size of the 3D model.

Your code about receiving the data looks good. After calling GetBody() you should be able to create the surface. Pass the bodydata pointer and bodydatasize to ClassEDisplay :: CreateSurface.