943,884 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 2408
  • C RSS
You are currently viewing page 3 of this multi-page discussion thread; Jump to the first page
Dec 23rd, 2007
1

Re: Including files at run time

You could do it something like that, but it introduces more problems than it solves:

fork() doesn't work on Windows. Even if it did, you would still need to set up some IPC to make things work right (that is, keep state, avoid excessive process loads and task switching, and I/O buffering, response time, and message configuration).

The simplest, and most common way to do it is to use DLLs. That's what they were designed for.

Windows provides protected memory accesses, so one DLL cannot easily gain access to another's process. Further, doing so would require source-code knowledge of the target DLL. Finally, a game will not function well if subprocesses don't behave (and try to disrupt their bretheren).


Another option, if you intend to have a "end-user programmable" AI, is to provide a basic language interpreter (embed Tcl or Python or somesuch), and execute each AI's code in a sandbox environment.
Featured Poster
Reputation Points: 1140
Solved Threads: 229
Postaholic
Duoas is offline Offline
2,039 posts
since Oct 2007
Dec 23rd, 2007
1

Re: Including files at run time

I had a problem which is something similar to what you are having, on how to interface the AI routine with my Code. But in my case the AI reasoning part part was done LISP. So for example if an Agent wanted to move from a point A to Point B there could be different path, which basically depends upon environment.

The LISP routine would normally find the path for me, the output of that function (Which is nothing out the path) will be sent to my C code using sockets.

You could use sockets to communicate between routines if your wanted. Which makes it more simple, some thing similar to RPC or RPCgen which you are requesting for a routine to be called on the server and the output of that function would directed to the client to the client.

Some alternative for you

ssharish
Reputation Points: 73
Solved Threads: 20
Posting Whiz in Training
ssharish2005 is offline Offline
253 posts
since Dec 2006
Dec 24th, 2007
0

Re: Including files at run time

@Duoas

Quote ...
You could do it something like that, but it introduces more problems than it solves:

fork() doesn't work on Windows. Even if it did, you would still need to set up some IPC to make things work right (that is, keep state, avoid excessive process loads and task switching, and I/O buffering, response time, and message configuration).
I agree.

Quote ...
Another option, if you intend to have a "end-user programmable" AI, is to provide a basic language interpreter (embed Tcl or Python or somesuch), and execute each AI's code in a sandbox environment.
I didn't understand this, Duoas. Please would you elaborate a bit? Terms like basic language interpreter and sandbox environment are completely new to me.

@ssharish2005
Quote ...
The LISP routine would normally find the path for me, the output of that function (Which is nothing out the path) will be sent to my C code using sockets.
Do you mean that I can send a value from a function written in one language to the main function written in another language using sockets? I'm new to the concept of sockets.

Quote ...
You could use sockets to communicate between routines if your wanted. Which makes it more simple, some thing similar to RPC or RPCgen which you are requesting for a routine to be called on the server and the output of that function would directed to the client to the client.
I don't know what is RPC and RPCgen . Are these related to sockets? From what you've given it seems it is related to networking.
Last edited by Jishnu; Dec 24th, 2007 at 5:19 am.
Reputation Points: 193
Solved Threads: 25
Posting Pro
Jishnu is offline Offline
518 posts
since Oct 2006
Dec 24th, 2007
1

Re: Including files at run time

Quote ...
Do you mean that I can send a value from a function written in one language to the main function written in another language using sockets? I'm new to the concept of sockets.
YES thats right, you call the routine which is written in a different language. But the calling procedure is language independent. It will vary from language to language. But, in LISP you have a inbuilt library which allows to do some socket manipulation.

Quote ...
I don't know what is RPC and RPCgen . Are these related to sockets? From what you've given it seems it is related to networking.
YES, it is something related to networking. But its is more often used in the UNIX world. I dunno about this on Windows though. I will have to research. RPC stand for Remote Procedure Call. So the name itself specific what it is suppose to do. You register all your routines on the server and the server will be waiting for the connection from the client and when once connected the client will request for a routine to be executed and the server will execute it and sends back the results to client across the network. Goggle "RPC Programming". This comes under a topic of Distributed Computing

ssharish
Reputation Points: 73
Solved Threads: 20
Posting Whiz in Training
ssharish2005 is offline Offline
253 posts
since Dec 2006
Dec 24th, 2007
0

Re: Including files at run time

Quote ...
Do you mean that I can send a value from a function written in one language to the main function written in another language using sockets? I'm new to the concept of sockets.
That's how the internet works -- its all done with sockets. Two programs running on the same or different computers can communicate with each other via sockets. And as explained by ssjarish it doesn't matter what computer language the programs are written in as long as that language supports sockets.
Last edited by Ancient Dragon; Dec 24th, 2007 at 7:51 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,952 posts
since Aug 2005
Dec 24th, 2007
0

Re: Including files at run time

Quote ...
And as explained by ssjarish it doesn't matter what computer language the programs are written in as long as that language supports sockets.
Do C and C++ support sockets? Are any special libraries required?
Reputation Points: 193
Solved Threads: 25
Posting Pro
Jishnu is offline Offline
518 posts
since Oct 2006
Dec 24th, 2007
0

Re: Including files at run time

Click to Expand / Collapse  Quote originally posted by Jishnu ...
Do C and C++ support sockets? Are any special libraries required?
YES, C\C++ support Socket/Network programming. Follow a link bellow for a good tutorial on socket and RPC programming.

Socket Programming
RPC Programming
RPCgen Programming

ssharish
Last edited by ssharish2005; Dec 24th, 2007 at 11:52 am.
Reputation Points: 73
Solved Threads: 20
Posting Whiz in Training
ssharish2005 is offline Offline
253 posts
since Dec 2006
Dec 25th, 2007
1

Re: Including files at run time

Quote originally posted by Jishnu ...
I didn't understand this, Duoas. Please would you elaborate a bit? Terms like basic language interpreter and sandbox environment are completely new to me.
For example, you could embed a Tcl interpreter in your program (TCL or Tool Command Language is a script language). Or, you could link a Python interpreter into your application.

In either case, you can extend the interpreted language itself to provide functionality specific to your application. Once done, the end-users could write their AI scripts in the embedded language (e.g. Tcl or Python), and your program will execute the end-user's code as needed.

The end-user's code would be a simple text file (just like all code files).

However, executing code you didn't write is a security concern, so you will need to implement the interpreter such that the end-user's code cannot do anything it shouldn't (like access files, or create sockets, etc.) Such an interpreter is said to exist in a sandbox --basically a controlled environment. Sand stays in; foreign material stays out.

Fortunately, this is very easy to do in Tcl and Python (and Scheme :-).


Socket programming is a pain in C/C++. If you were to embed Tcl or Python, you could use the embedded language's facilities to open and manage the socket. Both Tcl and Python make handling sockets trivial.


Whether you choose to do this or not you've got a lot of homework ahead of you. Good luck!
Featured Poster
Reputation Points: 1140
Solved Threads: 229
Postaholic
Duoas is offline Offline
2,039 posts
since Oct 2007
Dec 26th, 2007
0

Re: Including files at run time

Quote ...
Whether you choose to do this or not you've got a lot of homework ahead of you.
Yes, of course. These concepts are very much new to me and it will take quite a bit of time to have a decent grip over them. Thank you very much
Reputation Points: 193
Solved Threads: 25
Posting Pro
Jishnu is offline Offline
518 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: execl() to copy a file /bin/cp
Next Thread in C Forum Timeline: syntax question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC