Page 2 of 2

Re:Client/Server

Posted: Sun Nov 28, 2004 4:45 am
by Neo
Candy wrote: ... or dynamic_cast<ClientSocket>(object) it to the right type. If neither works, you are trying a really invalid assignment. Don't do that.
Does that mean I should write a constructor for the ClientSocket class that accpets a Socket as argument??

Re:Client/Server

Posted: Sun Nov 28, 2004 4:56 am
by Neo
Another thing I would also like to know is how to shutdown a server (not just using 'kill') from the command line itself. This is what i think should be done, please let me know if its right.
The server checks for command line args (CLA's) and if none are found then just start normally, by that i mean that the server will fork() a thread that will contain the execution logic of the server. This thread keeps on running forever (so i think i should ignore all interrupts??)
The program then returns to the command line (i think just not using wait() in the parent will make this possible ??
To shutdown i run the server with an CLA named say '-stop'
Now my problem here is how do i know which thread to kill if i am going to use 'kill()'

Or does anyone else have a better way of doing this whole thing??

Re:Client/Server

Posted: Sun Nov 28, 2004 10:29 am
by Candy
Neo wrote:
Candy wrote: ... or dynamic_cast<ClientSocket>(object) it to the right type. If neither works, you are trying a really invalid assignment. Don't do that.
Does that mean I should write a constructor for the ClientSocket class that accpets a Socket as argument??
Well.... no.

The dynamic_cast is identical to a normal cast ((ClientSocket *)object), except that it throws an exception if the object casted really isn't a client socket after all.

If you want your ServerSocket class to return ClientSocket's, make it return ClientSockets. If you want it to return Sockets, make it return Sockets and expect them in the receiving code. If you want it to return ClientSockets, but don't have a constructor for a client socket based on just a file descriptor, make one that does and make it protected, then make ServerSocket a friend of ClientSocket.

These are (afaik && imho) your best options.

Re:Client/Server

Posted: Mon Nov 29, 2004 8:01 am
by distantvoices
shouldn't the declaration of clientsocket cs be a pointer? like so: ClientSocket *cs; ?

Re:Client/Server

Posted: Mon Nov 29, 2004 11:16 am
by rich_m
On solaris when i need to compile my Socket programs i need to add the-lxnet or -lsocket arguments along with g++.
Why is this so? what are the actual libraries being linked in. I need to create a makefile for this but cant seem to get it done. Any help appreciated.

Re:Client/Server

Posted: Mon Nov 29, 2004 11:33 am
by Candy
rich_m wrote: On solaris when i need to compile my Socket programs i need to add the-lxnet or -lsocket arguments along with g++.
Why is this so? what are the actual libraries being linked in. I need to create a makefile for this but cant seem to get it done. Any help appreciated.
The -lsocket adds libsocket (from probably /usr/lib/* or /lib/*) to your program.

You do want to use them directly in your makefile.

PS: the solaris systems I can use also require -lnsl

Re:Client/Server

Posted: Tue Nov 30, 2004 7:27 am
by Neo
does the -lxnet do the same?

Re:Client/Server

Posted: Wed Dec 01, 2004 2:46 am
by Solar
-lanything links to libanything.

Re:Client/Server

Posted: Wed Dec 01, 2004 5:38 am
by Neo
Would be nice if anyone on Solaris could give me a makefile for some socket programming demo or something.

Re:Client/Server

Posted: Wed Dec 01, 2004 6:24 am
by distantvoices
maybe this is of use: http://pont.net/socket/

this line:

Code: Select all

solaris : gcc -Wall -o foo foo.c -lsocket -lnsl 
might be helpful.

Re:Client/Server

Posted: Wed Dec 01, 2004 7:11 am
by Neo
i wanted to create the object files separately to facilitate easier deployment.
Any help on that front?