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
Solved

Communication problem with CSocket -  CSocketFile - CArchive

Posted on 2002-05-29
7
593 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

789 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