OpenQNX :: The QNX Community Portal

May 13, 2008 - 12:33 PM
Google
  Web openqnx.com   
     Create an account Home · Submit News · QNX Forums · QNX Download · Search   
_
Main Menu
Who's Online
There are 59 unlogged users and 1 registered user online.

You can log-in or register for a user account here.

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
munder
Post subject: Client-server C program  PostPosted: May 21, 2007 - 12:10 PM
Active Member


Joined: Sep 24, 2006
Posts: 22

Can anybody send me a simple programs (client and server) written under QNX 6.3 with usage of MsgSend() and MsgReceive()?
 
 View user's profile Send private message  
Reply with quote Back to top
micro
Post subject: RE: Client-server C program  PostPosted: May 21, 2007 - 01:19 PM
Senior Member


Joined: Jul 22, 2004
Posts: 315

There is a quite good example for Server/Client within the docu under "name_attach()"
QNX NTO RTOS --> Library Reference --> N --> name_attach()
 
 View user's profile Send private message  
Reply with quote Back to top
munder
Post subject:   PostPosted: May 21, 2007 - 02:16 PM
Active Member


Joined: Sep 24, 2006
Posts: 22

Thanks Smile
 
 View user's profile Send private message  
Reply with quote Back to top
munder
Post subject:   PostPosted: May 22, 2007 - 09:39 AM
Active Member


Joined: Sep 24, 2006
Posts: 22

There's something I don't understand...
I want 2 computers to communicate in a local network.
I suppose that i should create global name.
So I have
attach = name_attach(NULL, ATTACH_POINT,NAME_FLAG_ATTACH_GLOBAL)
and in /dev/name/global I have my name.
So it seems like server is running properly.

In clients part I have:
name_open(ATTACH_POINT, NAME_FLAG_ATTACH_GLOBAL)
and client is ending here... ( EXIT_FAILURE ).

Can anybody know why? What should I do to make it work?
 
 View user's profile Send private message  
Reply with quote Back to top
mpwalter
Post subject:   PostPosted: May 22, 2007 - 11:40 AM
Active Member


Joined: Feb 07, 2006
Posts: 54

With name_attach("myName", local) you will create a channel in /dev/name/local/myName - this is to your server.

name_open("myName",local) will open/connect to your server about the channel "myName". name_open() will return a ID (like a filedescriptor, if -1 when fails) you use this value in MsgSend(). On your server you wait with MsgReceive().
 
 View user's profile Send private message  
Reply with quote Back to top
munder
Post subject:   PostPosted: May 22, 2007 - 11:52 AM
Active Member


Joined: Sep 24, 2006
Posts: 22

Are you saying that creating local server is enough? Earlier i did
name_attach(NULL, ATTACH_POINT,0)
and I had myName in /dev/name/local
On client I had
name_open(ATTACH_POINT, 0)

and it did't work.
name_open() didn't find myName...

So for my purposes local name creating will be good?
Why my client-server don't work?

Maybe problem is with gns? I checked and on server and on client it works as "client". Maybe this is the reason why my programs can't communicate?
If yes than what should I do to make that gns will work as server on my server-computer?
 
 View user's profile Send private message  
Reply with quote Back to top
mpwalter
Post subject:   PostPosted: May 22, 2007 - 12:06 PM
Active Member


Joined: Feb 07, 2006
Posts: 54

Ok, I misunderstand, your client and server will be run on two pc's right ? Then it is "right" that they didn't communicate, because the channel will only exist on the local machine.

What you need is the QNET functions like: ConnectAttacht() look in the IDE help for more informations about this functions
 
 View user's profile Send private message  
Reply with quote Back to top
munder
Post subject:   PostPosted: May 22, 2007 - 12:08 PM
Active Member


Joined: Sep 24, 2006
Posts: 22

So this sample that is available in Library Reference (name_attach()) will only work on 1 computer (ment client and server on the same computer)?
 
 View user's profile Send private message  
Reply with quote Back to top
mpwalter
Post subject:   PostPosted: May 22, 2007 - 12:17 PM
Active Member


Joined: Feb 07, 2006
Posts: 54

I don't know what you mean. Client run on one pc and the server on a second pc - right?!

For QNET look here in the IDE help:http://127.0.0.1:59062/help/topic/com.qnx.tools.ide.doc.pe/neutrino/sys_arch/qnet.html?resultof=%22%71%6e%65%74%22%20 (or search for: Native Networking).

Another way is to use TCP/IP sockets for communication. Do you want sent only short (!) messages or more ...?
 
 View user's profile Send private message  
Reply with quote Back to top
munder
Post subject:   PostPosted: May 22, 2007 - 12:21 PM
Active Member


Joined: Sep 24, 2006
Posts: 22

Link you gave doesn't work.
I have to use QNet. I know TCP/IP but my assumptions was different.
My messages would be rather short. Max 100 characters.
And yes I want to have client on one computer, and server on another.
I thought that this example is well for my needs
http://www.qnx.com/developers/docs/6.3.0SP3/neutrino/lib_ref/n/name_attach.html
What should I add to this example and where to make it work as I want?
 
 View user's profile Send private message  
Reply with quote Back to top
mpwalter
Post subject:   PostPosted: May 22, 2007 - 12:33 PM
Active Member


Joined: Feb 07, 2006
Posts: 54

Ok, try this:

name_attach(NULL,"myGlobalName",NAME_FLAG_ATTACH_GLOBAL) , so you attach the channel not local ...

The link is from the IDE help - here is the Internet link http://partners.qnx.com/developers/docs/6.3.0SP3/neutrino/user_guide/qnet.html
 
 View user's profile Send private message  
Reply with quote Back to top
munder
Post subject:   PostPosted: May 22, 2007 - 12:37 PM
Active Member


Joined: Sep 24, 2006
Posts: 22

As you can see before I did try global name and it didn't work Sad

So I'm asking again: how to make this example from Library reference work on 2 computers? (client and server on different computers)

Ok, it's not gns fault.
On my server I did: gns -s
and on client I did: gns -c
It didn't help (

Can anybody help me?
 
 View user's profile Send private message  
Reply with quote Back to top
ingraham
Post subject:   PostPosted: May 22, 2007 - 11:19 PM
Active Member


Joined: Nov 05, 2003
Posts: 56
Location: Texas
Normally on a single PC you use name_open() to return a coid and all is golden. In QNX 4.25, the equivalent function code also take a node number and again you were fine. For better or worse, this doesn't work in QNX 6.x

You have to switch from name_open() to ConnectAttach() to pass a node. The downside is that name_open() only needed a name, which you picked in advance and knew what it was. With ConnectAttach() you need the node, the process id (pid), and the channel id (chid). Getting the node is easy, assuming again you have a fixed node name known in advance. Call netmgr_strtond("nodename", NULL) and you get the nd to pass as the first argument to ConnectAttach(). But what about pid and chid? You could at least theoretically get the pid by looking at the processes running on the server machine, although there are lots of problems with that approach. But there's absolutely NO WAY to get the chid. Chid is returned from the name_attach() call on the server side, and the OS doesn't publish it.

You now have a chicken-and-egg problem. If you could attach to the server, you could request the pid and chid, but you need the pid and chid to attach to the server. THERE IS NO SOLUTION TO THIS PROBLEM WITHIN THE MESSAGE PASSING FRAMEWORK.

So how do you do it? You must step outside the message passing framework. There are numerous possibilities, but here are a few relatively practical ones:
1) After the server does its name_attach() call, it can write the pid and chid to a file with a predetermined path and name. Then just read the file over QNET from the client.
2) Use TCP/IP to get the pid and chid, then switch over to MsgSend/MsgReceive. This means that either the server must handle TCP/IP requests as well as QNX message passing, or a secondary server will be needed.
3) Write a resource manager, which will act like file-level IO. This looks a lot like choice 1, but with a lot more code. This happens to be the route that I picked when faced with this dilemna. I'm not convinced I made the right choice.

Final note: the 4th parameter to ConnectAttach() is index; set it to _NTO_SIDE_CHANNEL. The final parameter, flags, will probably be 0. So your to ConnectAttach() is:
Code:
// somehow get the pid
// somehow get the chid
int nd = netmgr_strtond("node_name", NULL);
// probably ought to error check nd here
coid = ConnectAttach(nd, pid, chid, _NTO_SIDE_CHANNEL, 0);
// really, really ought to error check coid

All that to replace coid = name_open("server_name", 0);

Hope that makes any kind of sense at all.

-James Ingraham
Sage Automation, Inc.
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
munder
Post subject:   PostPosted: May 23, 2007 - 05:21 AM
Active Member


Joined: Sep 24, 2006
Posts: 22

ingraham wrote:

1) After the server does its name_attach() call, it can write the pid and chid to a file with a predetermined path and name. Then just read the file over QNET from the client.


Thanks for your response. Only how to read the file that is on the server if I can't connect to server? I'm interested in the easiest and fastest way Smile

And silly question... What is "nodename"? Is it the name attached on server by name_attach()?

Btw it seems very complicated... Are you sure it's so difficult? QNX is well known for it's communication and to be frank I'm quite suprised with these difficulties Sad
 
 View user's profile Send private message  
Reply with quote Back to top
mario
Post subject:   PostPosted: May 23, 2007 - 12:19 PM
QNX Master


Joined: Sep 01, 2002
Posts: 2667

The code you posted should have worked localy and remotely. When you started gns -c did you provide the server name. Also if you read carefully the documentation you will notice that the server must support some QNX Messages in order to support gns.
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2007 The PNphpBB Group
Credits
All logos and trademarks in this site are property of their respective owners. The comments are property of their posters.
Powered by OpenQNX: The QNX Community Portal Site
QNX and the QNX logo are registered trademarks of QNX Software Systems.