Click to See Complete Forum and Search --> : three way communication


drewdaman
January 6th, 2005, 10:16 AM
hello everyone,

i need some more advice!

for the project i'm working on, i need to have three things: what i call a camClient, Server and Client. The camClient is a computer with a webcam attached to it. the server is of course the server. and the client is the real client. basically, this should happen: camCleints should connect to the server and send the stream from the webcam to the server. the REAL client must also be able to connect to the server and depending on a selection (of which camera to view) by the real client, the server must forward something coming in from one of the camClients. so,

one of the camClients -> Server -> real Client.

My question is about how to handle the connections for something like this. I know how to connect two things. i guess i will have to use separate sockets for Server-CamClient and Server-Client. But how should i distinguish between them (ie camclient and real client in the server) during the connection phase? I guess one way to do this would simply be to have a recv right after accept and have either type of client send a message identifying themselves. Is there a better way to do this, less error prone and more elegant?

also, just to let you know, i have not made the server multithreaded yet. so, it might not be very easy to have multiple camclients at the moment. but eventually, it will have to be able to do this.

i guess this is more of a "can you please comment" type question than a specific question! all comments appreciated!

thanks in advance!
drew.

Tomcat
January 7th, 2005, 03:06 AM
But how should i distinguish between them (ie camclient and real client in the server) during the connection phase? I guess one way to do this would simply be to have a recv right after accept and have either type of client send a message identifying themselves.
Another way would be to use different ports. Personally I think I would have some identification handshake with version information (to detect incompatibilities if I ever needed to change the protocol) and use different ports.

drewdaman
January 7th, 2005, 10:22 AM
hmm.. interesting.. but for the moment i just want to do a quick demo and not worry about multithreading. if i were to use listen... it would just block till it has a connection request would it not?

Mathew Joy
January 7th, 2005, 11:23 AM
i guess i will have to use separate sockets for Server-CamClient and Server-Client. Yes. You should have two socket handles to accept the connection that arrives.
But how should i distinguish between them (ie camclient and real client in the server) during the connection phase? I guess one way to do this would simply be to have a recv right after accept and have either type of client send a message identifying themselves. Is there a better way to do this, less error prone and more elegant?Well that is the best way. Upon connection, the camClient and the client will identify themselves, in the form of some message. Other ways are the port and the address. If the address is constant you can assume data comming from one adress as the camClient and the other, the client. Another alternative is to ask the clients to bind to some higher range ports so upon connection looking at the port, you can distinguish beween the client. The first method is the best and recomented, while if you are going for the second two, you may have to deal with change of address, and unavailability of desired port number.
also, just to let you know, i have not made the server multithreaded yet. so, it might not be very easy to have multiple camclients at the moment.But you already have multiple clients. Design properly, and multithreading won't be difficult to handle. I've posted a prototype design of a simple multithreaded server in this forum. Try searching, if you can't find let me know.

drewdaman
January 7th, 2005, 05:34 PM
ok.. thanks for replying. i guess i will try it that way.

matthew, i searched for your multithreaded server code but couldn't find it. do you think it would be possible for you to either attach it here or email it to me at dhruv22@gmail.com?

thanks a lot!