Re: Winsock / Sockets programming
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Tue, 08 Jul 2008 18:47:12 -0400
See below...
On Tue, 8 Jul 2008 08:15:42 -0700 (PDT), Peter <pvrequiz@xxxxxxxxx> wrote:
Working with Winsock****
I am making this post because I need help with Winsock Programming.
About the application: I want to create a client/server application.
At the client side receive message from the server only, send message
to the server only. In the Server side receive message from all the
clients, broadcast message, and send message to individual clients.
Who sends and who doesn't send is irrelevant to the architecture; it is a detail of the
protocol
****
*****
So far, I have read some information about Winsock, and I have managed
to create in a dialog application the win console application example
on.
http://www.codeproject.com/KB/cpp/chat_client_server.aspx
But I am having problem when I want to create different sockets so
allocate it to more than one machine.
I have no idea what you mean by this question.
A target of a network connection is a <ip-address, socket#> pair. Therefore, you would
typically assign a socket number to your application (if this is going to be distributed
outside the walls of your environment, you should apply to IANA for a Registered Port
Number) and every server that supports this would have that socket number. Now you need
to find the server that exports the port.
There are network front-ends that do this; this is what most server farms use. The IP
address is the IP address of the "front end" and the system does "load balancing" to
ensure that the connections are distributed around the many servers behind the front-end
machine. Thus, it is a form of proxy server. You can buy hardware that does this, or buy
software you can run on a server, or write your own.
Otherwise, the client has to know the IP address of each potential server.
****
****
The 2 problem I am facing now is I am not sure if I should create one
socket on one port. And connect everybody to that socket like a big
chat room and do the sorting/find at the CString buffer, the problem I
see is that all the end user will need to be looking for their message
in a big CString buffer.
Huh? That's *all* you can do, ever, under any conditions. But I don't get what you are
talking about here. When you create a listener port, you create a listener port. That's
all. For example, <192.168.168.4, 17000> (port # 17000, to choose a random number, on
host 192.168.168.4). When you do an Accept, a *brand new* socket is created for that
communication, so there is no "sorting out" to do at all. The socket receives data from
the remote client, or sends data to the remote client, and that's it. There is no
"sorting" or "giant CString" or anything like that. If you have 100 connections, you will
have 101 CAsyncSocket objects (you will *never* use CSocket, ever, for any reason
whatsoever); one is the listener socket and the other 100 are the individual connections.
*****
****
The second approach will be create socket to each client
There is no other way to do TCP/IP, and UDP rarely makes sense except in some very
restricted contexts, all other uses are uninteresting.
****
(at this****
point I am not sure if you can create more than one socket attached to
the same port, remember I want to sent message to a unique client at a
time. In my try application if I don?t disconnect/destroyed the socket
and create it again when I receive a message from the server I receive
it twice, telling me I can have more that one socket to attached at
the same port, but I am not sure if I can send it to a particular
socket or it just broad cast because it is attached to the same port.)
I have no idea what any of this means. If your client closes the socket, the server gets
an OnClose notification and closes its socket. It makes no sense to keep it open because
it isn't connected to anything! The rest of the description just doesn't make any sense.
****
I could allocate a port and a socket to each client so every one has****
his own socket and port attached, but this approach could ending me up
with a server that need to be looking for 200+ ports
That's how it is done. There is no other way. Are you under the impression that sockets
are expensive?
****
Joseph M. Newcomer [MVP]
Let discuss this problem only here because the second problem depend
on what approach I go ahead.
Thank you for your help,
Regards
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- Winsock / Sockets programming
- From: Peter
- Winsock / Sockets programming
- Prev by Date: Re: Menu type conversion
- Next by Date: Re: WM_TIMER prevents window from being displayed ???
- Previous by thread: Re: Winsock / Sockets programming
- Next by thread: Re: Winsock / Sockets programming
- Index(es):
Relevant Pages
|