Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WinSock Query?

Status
Not open for further replies.

allenboopreski

Programmer
Mar 3, 2003
1
IN
Hi All,
I have just started to learn Windows Socket Programming.I have read all the relevant content in MSDN and has got fair bit of idea about classes like CSocket CAsynSocket CArchive and CSocketFile.

I have got quite a few questions to ask like:

1. Is it possible to call from client side a function that is defined at the server side which would in turn return me a buffer?

2. What would happen if the data from server side is coming to the client side and the internet connection brokes off.?

3. When using Stream Sockets for communication over TCP/IP
what is the success rate that the data will be delivered from client to server or from server to client?
 
>> 1. Is it possible to call from client side a function that is defined at the server side which would in turn return me a buffer?

You can't directly call functions with sockets, however most application-level protocols arrange the data into "messages", each of which have a header that includes a "message code." (The nomenclature may vary.) If you're deriving from CAsyncSocket, overload OnReceive() to handle incoming messages. For example
[tt]
void CMySocket::OnReceive([/tt]/* no parameters i think */[tt])
{
DWORD dwMessageCode, dwMessageSize;

Receive(&dwMessageCode,4);
Receive(&dwMessageSize,4);

[/tt]// Make sure message size is under 64K, to keep[tt]
[/tt]// hackers from allocating all your memory.[tt]
if (dwMessageSize > 65536) {
Close();
return;
}

void* pmsg = malloc(dwMessageSize);

switch(dwMessageCode) {
[/tt]// ...[tt]
}

free(pmsg);
}[/tt]

>> 2. What would happen if the data from server side is coming to the client side and the internet connection brokes off.?

Your client socket's OnClose function will be called. If you were in the middle of sending, then that message won't be sent.

>> 3. When using Stream Sockets for communication over TCP/IP what is the success rate that the data will be delivered from client to server or from server to client?

100%. If you send data, it will reach the client, unless the connection is reset.

[cheers]
 
well, the way you could call a function on the server side from the client side for example is when you push a button it sends a string.. say the string sent is "doFunction1", you could program the servers OnReceive() function with a switch ir a series of If statements, that checks the strings it is receiving..

if(strReceivedMessage == "doFucntion1")
function1(); // call function1

is that what you were asking?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top