Solved

Communication problem with CSocket -  CSocketFile - CArchive

Posted on 2002-05-29
7
587 Views
Last Modified: 2013-11-20
Hi,
I try to implement a small socket app, a server and a client. The server just should print out, what the client send to him.
I think that the connections stand, but the communication doesn't work. If I try to read from the archive at the server side, it throws an ugly error, if i try to evaluate Archive::IsBufferEmpty, it's always empty. But the client permanently send the string "hallo" and flushes.
I have no any ideas left, here comes the code :

bool CSocket1Dlg::Server()
{
     CSocket ServerSocket;

     UpdateData();

     if( ! m_Socket.Create( m_iPort ) )
     {
          AfxMessageBox( _T("Couldn't create Serversocket"));
          return false;
     }
     if( ! m_Socket.Listen() )
     {
          AfxMessageBox( _T("Couldn't listen at Serversocket"));
          return false;
     }
     m_Socket.Accept( ServerSocket );

     CSocketFile SockFile( & m_Socket );
     CArchive     Archive( & SockFile, CArchive::load );

     while( 1 )
     {
          if( ! Archive.IsBufferEmpty() )
          {
               Archive >> m_sEditRead;

               m_EditRead.UpdateData( false );
               m_EditRead.RedrawWindow();
          }
     }

     return true;
}

bool CSocket1Dlg::Client()
{
     CString s("H A L L O");
     UpdateData();

     if( ! m_Socket.Create() )
     {
          AfxMessageBox( _T("Couldn't create Clientsocket"));
          return false;
     }
     m_Socket.Connect( getIPAdressString(), m_iPort );

     CSocketFile SockFile( & m_Socket );
     CArchive     Archive( & SockFile, CArchive::store );

     while( 1 )
     {
          Archive << s;
          Archive.Flush();
     }

     return true;
}

thanxs a lot
0
Comment
Question by:DennisWood
  • 4
  • 2
7 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 7041453
How you run client and server in the same thread.

u are using the infinite loop .
So the server never get a chance to connect...

Roshmon
0
 
LVL 22

Expert Comment

by:ambience
ID: 7041476
are you using multiple threads ? , if not then you should.

try spawning the server thread first and maybe with a higher priority than the client thread.

Or better yet put a delay in client, so as to give the server a fair chance to catch up.
0
 

Author Comment

by:DennisWood
ID: 7042102
Sorry, it looks a little bit confusing, in fact it's one application, but i start two instances, one as client, the other one as server. The infinite loops is just while i'm still testing, but all networkfunctionality is in the two methodes. Nothing gets initializied in another part.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Accepted Solution

by:
ambience earned 200 total points
ID: 7043606
CSocketFile SockFile( & m_Socket );

change that to

CSocketFile SockFile( & ServerSocket);
   
0
 

Author Comment

by:DennisWood
ID: 7044937
OK I'll try it, would maybe take until monday, cause I don't have windowsaccess
0
 

Author Comment

by:DennisWood
ID: 7046397
Sorry, but it still won't work. I'm really out of any idea solving this problem.
0
 

Author Comment

by:DennisWood
ID: 7066764
Now I've just have a "workaround", byletting the CArchive away.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now