Client/Server

Programming, for all ages and all languages.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Client/Server

Post 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??
Only Human
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Client/Server

Post 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??
Only Human
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Client/Server

Post 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.
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Client/Server

Post by distantvoices »

shouldn't the declaration of clientsocket cs be a pointer? like so: ClientSocket *cs; ?
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
rich_m

Re:Client/Server

Post 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.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Client/Server

Post 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
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Client/Server

Post by Neo »

does the -lxnet do the same?
Only Human
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Client/Server

Post by Solar »

-lanything links to libanything.
Every good solution is obvious once you've found it.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Client/Server

Post by Neo »

Would be nice if anyone on Solaris could give me a makefile for some socket programming demo or something.
Only Human
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Client/Server

Post 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.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Client/Server

Post by Neo »

i wanted to create the object files separately to facilitate easier deployment.
Any help on that front?
Only Human
Post Reply