| | |
Including files at run time
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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.
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.
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
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
@Duoas
I agree.
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
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.
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.
•
•
•
•
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).
•
•
•
•
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.
@ssharish2005
•
•
•
•
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.
Last edited by Jishnu; Dec 24th, 2007 at 5:19 am.
"You know you're a computer geek when you try to shoo a fly away from the monitor screen with your cursor. That just happened to me. It was scary." - Juuso Heimonen.
"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
•
•
•
•
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.
•
•
•
•
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.
ssharish
•
•
•
•
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.
Last edited by Ancient Dragon; Dec 24th, 2007 at 7:51 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
•
•
And as explained by ssjarish it doesn't matter what computer language the programs are written in as long as that language supports sockets.
"You know you're a computer geek when you try to shoo a fly away from the monitor screen with your cursor. That just happened to me. It was scary." - Juuso Heimonen.
"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
•
•
•
•
Do C and C++ support sockets? Are any special libraries required?
Socket Programming
RPC Programming
RPCgen Programming
ssharish
Last edited by ssharish2005; Dec 24th, 2007 at 11:52 am.
•
•
•
•
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.
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!
•
•
•
•
Whether you choose to do this or not you've got a lot of homework ahead of you.
"You know you're a computer geek when you try to shoo a fly away from the monitor screen with your cursor. That just happened to me. It was scary." - Juuso Heimonen.
"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
![]() |
Similar Threads
- functions in header files (C++)
- General Tips for Mac OS X (Mac tips 'n' tweaks)
- can't run ad-aware se (Viruses, Spyware and other Nasties)
- Modem keeps dialling when i open files (Viruses, Spyware and other Nasties)
- Ok, It's Linux time! (Getting Started and Choosing a Distro)
- XP Boot problems due to virus? (Viruses, Spyware and other Nasties)
- Exchange server 2000 problems (Networking Hardware Configuration)
- Need some help plz; ima newb (not sure how to catagorize this particular prob) (C++)
- Norton WMI Update doesn't work (Viruses, Spyware and other Nasties)
- Browser hijacked - returns every time I Start (Viruses, Spyware and other Nasties)
Other Threads in the C Forum
- Previous Thread: execl() to copy a file /bin/cp
- Next Thread: syntax question
| Thread Tools | Search this Thread |
* ansi api append array arrays bash binarysearch calculate centimeter changingto char character convert copyanyfile copypdffile creafecopyofanytypeoffileinc createcopyoffile createprocess() dynamic execv fflush file floatingpointvalidation fork forloop frequency function getlogicaldrivestrin givemetehcodez grade graphics gtkwinlinux histogram homework i/o ide inches include infiniteloop initialization input intmain() iso keyboard km license linked linkedlist linux list looping loopinsideloop. lowest matrix microsoft multi mysql oddnumber open opendocumentformat openwebfoundation overwrite pdf pointer pointers posix power program programming pyramidusingturboccodes radix read recursion recv recvblocked reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string strings suggestions test testautomation threads unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi






