Skip navigation.
Home
The QNX Community Portal

View topic - Client-server C program

Client-server C program

This is where you can ask a software to be ported or written for QNX. You can also request to buy/sell second hand software.

Client-server C program

Postby munder » Mon May 21, 2007 12:10 pm

Can anybody send me a simple programs (client and server) written under QNX 6.3 with usage of MsgSend() and MsgReceive()?
munder
Active Member
 
Posts: 22
Joined: Sun Sep 24, 2006 11:57 am

RE: Client-server C program

Postby micro » Mon May 21, 2007 1:19 pm

There is a quite good example for Server/Client within the docu under "name_attach()"
QNX NTO RTOS --> Library Reference --> N --> name_attach()
micro
Senior Member
 
Posts: 458
Joined: Thu Jul 22, 2004 8:41 pm

Postby munder » Mon May 21, 2007 2:16 pm

Thanks :)
munder
Active Member
 
Posts: 22
Joined: Sun Sep 24, 2006 11:57 am

Postby munder » Tue May 22, 2007 9:39 am

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?
munder
Active Member
 
Posts: 22
Joined: Sun Sep 24, 2006 11:57 am

Postby mpwalter » Tue May 22, 2007 11:40 am

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().
mpwalter
Active Member
 
Posts: 56
Joined: Tue Feb 07, 2006 9:20 am

Postby munder » Tue May 22, 2007 11:52 am

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?
munder
Active Member
 
Posts: 22
Joined: Sun Sep 24, 2006 11:57 am

Postby mpwalter » Tue May 22, 2007 12:06 pm

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
mpwalter
Active Member
 
Posts: 56
Joined: Tue Feb 07, 2006 9:20 am

Postby munder » Tue May 22, 2007 12:08 pm

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)?
munder
Active Member
 
Posts: 22
Joined: Sun Sep 24, 2006 11:57 am

Postby mpwalter » Tue May 22, 2007 12:17 pm

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 ...?
mpwalter
Active Member
 
Posts: 56
Joined: Tue Feb 07, 2006 9:20 am

Postby munder » Tue May 22, 2007 12:21 pm

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. ... ttach.html
What should I add to this example and where to make it work as I want?
munder
Active Member
 
Posts: 22
Joined: Sun Sep 24, 2006 11:57 am

Postby mpwalter » Tue May 22, 2007 12:33 pm

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
mpwalter
Active Member
 
Posts: 56
Joined: Tue Feb 07, 2006 9:20 am

Postby munder » Tue May 22, 2007 12:37 pm

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?
munder
Active Member
 
Posts: 22
Joined: Sun Sep 24, 2006 11:57 am

Postby ingraham » Tue May 22, 2007 11:19 pm

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: Select all
// 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.
ingraham
Senior Member
 
Posts: 160
Joined: Wed Nov 05, 2003 2:25 pm
Location: Texas

Postby munder » Wed May 23, 2007 5:21 am

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 :(
munder
Active Member
 
Posts: 22
Joined: Sun Sep 24, 2006 11:57 am

Postby mario » Wed May 23, 2007 12:19 pm

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.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Next

Return to Request Software

Who is online

Users browsing this forum: No registered users and 2 guests