Just be carefull, your char array has to be null-terminated to be used to initialize a CString like that or even if you use the = operator ( CString str; str = charr; ). Othwerwise it will keep on reading characters till it finds a null character somewhere after your array and which either results in access violation OR you get garbage in your str.
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <
I have client and server . hundred of client connect to the server . and I am serving the data to the client
but not every client is getting data . why it is happening . I think this is due to winsock internal buffer
is there way to increase winsock internal buffer . i am using TCP/IP socket
I agree with CPallini, this is unlikely to be related to an internal buffer. We would need more detailed information to help you with your problem, here are some suggestions to look at:
1) Check in the server code that you are actually sending complete data package to every client, e.g. by comparing that the return value from send() is equal to the number of bytes and that there were no errors. A server should be able to handle a couple of thousand clients, make sure you are not running into a OS specific upper limit.
2) Check in the client code that you are actually connected to the server and debug received data, e.g. print out the number of received bytes from recv(). TCP is a stream oriented protocol, which means that when the server sends 100 bytes you might get 100 bytes or chunks of 2 times 50 bytes etc (this could confuse the receiving side).
3) If you are new to network programming it is always good to start with working examples. Have a look at Beej's guide to networking programming[^] and Winsock Programmer's FAQ[^], there are client/server examples in section 6.
I am using windows server 2003 and currently 200 clients connected to it regularly.
all clients are connected fine. I am sending the data to the clients frequently .
I am getting data from the data base .and using the timer of 100 miliseconds . as data change
I send the data to the client in loop one by one . every time it monitor on 100 ms for change in
database. some clients not getting data . and on next timer they get the data . problem is
occuring to any client randomly .
What I find strange is that you send data to all clients and some miss one data set. With a TCP stream it is not possible that the socket forgets or jumps over one data set. I suspect that the problem is in your application code, please have a look at my previous posting and do some debugging on server and client side. If possible try to isolate the problem, provide more information or source code. In any case, a few hundred clients are no problem for your OS.
When you encounter and error while sending check what error code[^] you got. From MSDN:
If no error occurs, send returns the total number of bytes sent, which can be less than the number requested to be sent in the len parameter. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.
An operation on a socket or pipe was not performed because the system lacked sufficient buffer space or because a queue was full. WinSock was unable to allocate additional memory to accommodate the function request. This error indicates a shortage of resources on your computer.[...]
I am just guessing here. If this indeed a resource problem, can you try to close unneeded applications (also make sure you do not have a memory leak in your application) and alternatively run your software on a PC with more RAM? Another way to diagnose the problem, limit the server to 100 connections and then increase the value until you hit the problem (keep an eye on the overall system memory consumption e.g. with 'Windows Task Manager').
Are they all directly on the internet or are they hding behind NAT? If so you need to makwe sure you have NAT traversal enabled in the proxies.
answer : they all are directly on the internet
A Broadcast address (255.255.255.255) is for all devices on the subnet. A Unicast address is for one machine.
answer : This is not Broadcast sure . I donot know unicast
If you cant ping I dont see how you can sockets to work.
answer : server on public IP you can ping any where from world no proxy nat at all
ARP is hardware to IP address mapping. If you are on a LAN this is important, and thats the normal place to use sockets. On a pure IP backbone ARP isnt used of course.
answer : I think there is no need
Ditto the network cards.
And you say on some machines the sockets work. Hmmm.... client to server, or server to client (ie which is the watcher and which is opening the socket)?
answer : server on public IP is listener . and client on any where in the world open socket communication with the server with IP and port number
Even on th eones that work, ie the watcher can accept an incoming socket open, can it respond sucessully with that response arriving at the initiator?
answer : it respond succesfuully with the server
I think NAT is going to kill this dead. You need to have NAT traversal at least to have your clients IP addresses public enough to be visible to the server
answer : on one timer tick (usually 100ms) any client get the data and on next tick donot get and again get on next tick . this is happening randomly with all clients ,and I am sure all clients are connected sussefully to the server.