| Author |
Message |
|
|
Post subject: Client-server C program
Posted: 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()? |
|
|
| |
|
|
|
 |
|
|
Post subject: RE: Client-server C program
Posted: 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() |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: May 21, 2007 - 02:16 PM
|
|
Active Member
Joined: Sep 24, 2006
Posts: 22
|
|
Thanks  |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: 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? |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: 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(). |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: 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? |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: 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 |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: 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)? |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: May 22, 2007 - 12:17 PM
|
|
Active Member
Joined: Feb 07, 2006
Posts: 54
|
|
|
|
|
 |
|
|
Post subject:
Posted: 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? |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: May 22, 2007 - 12:33 PM
|
|
Active Member
Joined: Feb 07, 2006
Posts: 54
|
|
|
|
|
 |
|
|
Post subject:
Posted: 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
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? |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: 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. |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: 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
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  |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: 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. |
|
|
| |
|
|
|
 |
|
|