Solved

Communication problem with CSocket -  CSocketFile - CArchive

Posted on 2002-05-29
7
600 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

707 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