473,507 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Communications Breakdown with CSocket

The following describes a problem I have been having for the better
part of 3 months, for approximately the last month however I have been
focused solely on solving it and seem to be no nearer now than a month
ago. Any thoughts or suggestions that might lead to a fix would be
greatly appreciated.

I have to VB based applications on two different PC's, a client and a
server which use a pair of OCX's to provide a communication method
between the two and which use an overloaded version of the CSocket
class.

A problem has arisen where communication between the two OCX's will be
interrupted. The socket will appear to remain open as the
Disconnection event on either side has not been fired, however neither
side is able to hear the other (even when sending on the other side is
occurring).

While not 100% predictable, the only times the communication breaks
down is when the method SendPlayList or one of a couple other Server
side OCX methods fire which send a string. Note: These functions to
not cause a break down each time they are called, but seem to
ultimately be responsible for the break down.

In trying to track down this issue, I have implemented critical
sections on both the client and server side (sending and receiving
both) to help to ensure that multiple sends or processing of received
data does not occur. I have also implemented basic checking (to be
removed later) to ensure that that the correct amount of data is being
sent and received each time.

Below is some of the code being worked with:

On the VB server side, we have the server OCX instantiated and named
Remote, we call the SendPlayList method of it, passing the string
sPlayList as such:
Remote.SendPlayList sPlayList
Within the server side OCX, the above line calls the following
function:

void CSRemoteCtrl::SendPlayList(LPCTSTR PlayList)
{
PACKET_HEADER hdr;
BYTE* pData;
int iBufSize;
SendCriticalSection.Lock();
if (lstrlen(PlayList) > 0)
{
if (m_pClientSocket != NULL)
{
hdr.cmd = SERVER_PLAY_LIST;
hdr.size = lstrlen(PlayList)+1; // +1 for NULL terminator

iBufSize = sizeof(PACKET_HEADER) + hdr.size;

pData = new BYTE[iBufSize];
memcpy( &pData[0], &hdr, sizeof( PACKET_HEADER ));
memcpy( &pData[sizeof(PACKET_HEADER)], PlayList, hdr.size);

int iRet = m_pClientSocket->Send(pData, iBufSize);
if(iRet != iBufSize)
AfxMessageBox("Disconnected due to wrong count of bytes sent");

delete [] pData;
}
}
else
{
hdr.cmd = SERVER_PLAY_LIST;
hdr.size = 0;

int iRet = m_pClientSocket->Send(&hdr, sizeof(PACKET_HEADER));
if(iRet != sizeof(PACKET_HEADER))
AfxMessageBox("Disconnected due to wrong count of bytes sent");
}
}
On the receiving side within the client OCX, the OnReceive function
fires when new data arrives, inside of it there is a switch statement
which contains the following:

Receive( &packetCommand, sizeof( packetCommand ), MSG_PEEK );

switch( packetCommand )
{

//... Other Case Statements

case SERVER_PLAY_LIST:
{
PACKET_HEADER packet;

// Receive the packet structure
iRet = Receive( &packet, sizeof( packet ));
if(iRet != sizeof(packet))
AfxMessageBox("Size Error 1 in: SERVER_PLAY_LIST");
// Catch the file if it is attached
if( packet.size > 0)
{
char *filenames = new char[ packet.size ];
iRet = Receive( filenames, packet.size );
if((UINT32)iRet != packet.size)
AfxMessageBox("Size Error 2 in: SERVER_PLAY_LIST");
// Activate the event
pCRemoteCtrl->FirePLAYLIST( handle, filenames );

delete filenames;
}
else
{
// Activate the event
pCRemoteCtrl->FirePLAYLIST( handle, "" );
}
}
break;
//... Other Case Statements

}
A couple of conventions being used here is that the packets I am using
have a header sections which contain an enumerated value which
describes the kind of packet it is, based on that, a different type of
payload packet will be used to read the data and process it, similar
to how the sending side works.

Most of the time, the above code, along with similar blocks functions
flawlessly, but now and then, this or several others can and does
bring down the communication.

Also, this code is the 3rd version of code which has been used in the
same way (providing TCP/IP connectivity between VB apps) and is the
first to exhibit these problems, thus I require an easy to implement
solution which does not require rewriting or modifying large sections
of it.
Jul 22 '05 #1
5 1791
Brendan Grant wrote:
The following describes a problem I have been having for the better
part of 3 months, for approximately the last month however I have been
focused solely on solving it and seem to be no nearer now than a month
ago. Any thoughts or suggestions that might lead to a fix would be
greatly appreciated.

I have to VB based applications on two different PC's, a client and a
server which use a pair of OCX's to provide a communication method
between the two and which use an overloaded version of the CSocket
class.

<snip MFC code>

Only the standard C++ language and its library are topical here. MFC
questions should be asked on microsoft.public.vc.mfc.

- Pete

Jul 22 '05 #2
> Only the standard C++ language and its library are topical here. MFC
questions should be asked on microsoft.public.vc.mfc.


I know, and have done so. Unfortunately being unable to find an answer
most anywhere I have looked, I have been forced to expand my search
for a solution to just outside of the normal area.
Jul 22 '05 #3
Brendan Grant wrote:
Only the standard C++ language and its library are topical here. MFC
questions should be asked on microsoft.public.vc.mfc.


I know, and have done so. Unfortunately being unable to find an answer
most anywhere I have looked, I have been forced to expand my search
for a solution to just outside of the normal area.


Well, that still does not make it topical here. :)
Would you ask your question, say, rec.gardens.cacti? Your question has
nothing to do with the topic of that group, and not this one either.

- Pete
Jul 22 '05 #4
"Pete C." <x@x.x> wrote in message news:<fPkyc.1815>
Well, that still does not make it topical here. :)
Would you ask your question, say, rec.gardens.cacti? Your question has
nothing to do with the topic of that group, and not this one either.

- Pete


Your comparison is completely without merit.

Most MFC programming is done in and with C++, so it is not too long of
a shot to think that someone on a C++ group might have encountered
this problem in their time who does not read an MFC group.

It is far less likely that such a person would read rec.gardens.cacti
and be a MFC or C++ programmer.

My question, being based in C++ does thus still have a place in a
group such as this.
Jul 22 '05 #5
gr****@dahat.com (Brendan Grant) wrote in message news:<d5**************************@posting.google. com>...
"Pete C." <x@x.x> wrote in message news:<fPkyc.1815>
Well, that still does not make it topical here. :)
Would you ask your question, say, rec.gardens.cacti? Your question has
nothing to do with the topic of that group, and not this one either.

- Pete


Your comparison is completely without merit.

Most MFC programming is done in and with C++, so it is not too long of
a shot to think that someone on a C++ group might have encountered
this problem in their time who does not read an MFC group.

It is far less likely that such a person would read rec.gardens.cacti
and be a MFC or C++ programmer.

My question, being based in C++ does thus still have a place in a
group such as this.


The topic of the group is *Standard* C++, and not MFC. In your code,
there are lots of identifiers which are neither part of the Standard
Library, nor have you declared them yourself.

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
To iterate is human, to recurse divine.
-L. Peter Deutsch
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2053
by: kids | last post by:
Can i post question related to CSocket here? Thanks
0
2484
by: Dana Morris | last post by:
Call for Participation OMG's First Annual Software-Based Communications (SBC) Workshop: From Mobile to Agile Communications http://www.omg.org/news/meetings/SBC2004/call.htm September 13-16,...
1
1484
by: Catherine Jo Morgan | last post by:
This is for a recreational tree climbing database. When a climb is arranged, it often begins with one or more inquiries by phone or email. Sometimes it takes several communications to answer...
6
6956
by: Peter Krikelis | last post by:
Hi All, I am having a problem setting up input mode for serial communications. (Sorry about the long code post). The following code is what I use to set up my comm port.
1
2279
by: Bryan | last post by:
I have created an MFC ActiveX control. If I connect to my local machine on some port, everything works fine. If I try to connect to a different computer, I get an error (from CSocket.Create) that...
0
2129
by: BuddyWork | last post by:
Hello, I want to know if there any good tools out there which will show me a breakdown of the memory allocation in Gen 2 heap, basically a breakdown by object is what I'm looking for. The...
4
2974
by: Gary Frank | last post by:
I'd like to write a program in VB.Net that handles serial communications to several devices. VB.Net 2003 does not have adequate built-in serial communications. I heard that 2005 will have that. ...
0
1115
by: hsdas | last post by:
Hi, I started using CSocket as Winsock Control in VB6 do not allow to transfer UDTs. Can anybody who have used CSocket show me some light on how to use CSocket to Send and Receive UDTs....Quick help...
3
4575
by: Daron | last post by:
Is it possible to use SQL to take a field, and break it down by denominations? I would like to take a field, and then break this out into the number of bills($100's, $50's, etc) I would need:...
0
7111
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7485
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.