Including files at run time

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Including files at run time

 
1
  #21
Dec 23rd, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 241
Reputation: ssharish2005 is on a distinguished road 
Solved Threads: 20
ssharish2005's Avatar
ssharish2005 ssharish2005 is offline Offline
Posting Whiz in Training

Re: Including files at run time

 
1
  #22
Dec 23rd, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 514
Reputation: Jishnu will become famous soon enough Jishnu will become famous soon enough 
Solved Threads: 26
Jishnu's Avatar
Jishnu Jishnu is offline Offline
Posting Pro

Re: Including files at run time

 
0
  #23
Dec 24th, 2007
@Duoas

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.

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
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.

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.
"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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 241
Reputation: ssharish2005 is on a distinguished road 
Solved Threads: 20
ssharish2005's Avatar
ssharish2005 ssharish2005 is offline Offline
Posting Whiz in Training

Re: Including files at run time

 
1
  #24
Dec 24th, 2007
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.

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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,445
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1475
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Including files at run time

 
0
  #25
Dec 24th, 2007
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.
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 514
Reputation: Jishnu will become famous soon enough Jishnu will become famous soon enough 
Solved Threads: 26
Jishnu's Avatar
Jishnu Jishnu is offline Offline
Posting Pro

Re: Including files at run time

 
0
  #26
Dec 24th, 2007
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?
"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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 241
Reputation: ssharish2005 is on a distinguished road 
Solved Threads: 20
ssharish2005's Avatar
ssharish2005 ssharish2005 is offline Offline
Posting Whiz in Training

Re: Including files at run time

 
0
  #27
Dec 24th, 2007
Originally Posted by Jishnu View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Including files at run time

 
1
  #28
Dec 25th, 2007
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!
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 514
Reputation: Jishnu will become famous soon enough Jishnu will become famous soon enough 
Solved Threads: 26
Jishnu's Avatar
Jishnu Jishnu is offline Offline
Posting Pro

Re: Including files at run time

 
0
  #29
Dec 26th, 2007
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
"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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC