I'm pretty new to Unix coding and would like to work on a few simple networking projects. I found a few tutorials that are exactly what I am looking for - this one in particular: http://www.linuxhowtos.org/C_C++/socket.htm.
I have figured out how to compile the server and client c files into executables, and I can run them in the terminal like this:
open server
open client
since I'm using Mac OS X 10.7.5. My problem is that I need to pass arguments to these programs when I initialize them. The tutorial uses this code:
server 51717
client clientName 51717
but I haven't found a way to replicate that in my Mac terminal.
open server --args 51717 //doesn't work
I found this post and created an applescript with this code
do shell script "open -a /Desktop/server --args 51717"
but that throws a bunch of errors. I tried many variations but couldn't get any to run. I also couldn't get the Chrome example working from that post (I don't have FF installed).
How do I pass a simple integer port number as an argument to the program like in the tutorial? Is this easier to do on a Linux machine? I have no problem switching OS's at this point, and it would be ideal if i could use the 'server 51717' syntax that the tutorial uses instead of having to create a separate run script for each program. Looking for an answer and advice. Thanks.
EDIT:
I have gotten it to run correctly, but somethings still not working right. I start the server like this:
$ ./server 3456
then open a new terminal and start the client with limited success:
$ ./client mClient 3456
ERROR, no such host
$ ./client 127.0.0.1 3456
Please enter the message: //running correctly
//... this also works
$ ./client 127.1 3456
Please enter the message: //running correctly
I can start the client with some number.number combinations but it doesn't work for all of them and I can't use any letters. Why does only one of these solutions work?
SOLUTION:
$ sudo nano /private/etc/hosts
add 127.0.0.1 mClient
to the bottom then press Ctrl^o to save
Now this works:
$ ./client mClient 3456