Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have server(TCP/IP) code written in c++ which uses CArchieve with windows sockets as mention here in msdn
http://msdn.microsoft.com/en-us/library/ya4826hx(v=vs.80).aspx[^].


When i try to connect it using clients written in c++, it works fine.

But if i try to connect using c# client, it doesn't get connected.

In the server code i have CArchieve along with socket to listen to data from clients. Is there some way i can use c# client to send data ? server is using CArchieve class along with sockets. How can make a client in c# which send data same as CArchieve in MFC

[edit]

This is my c++ code for creating sockets

C++
bool TestApp::CreateSockets()
{
 ///////////////////////////////////////////////////////////////////////////
 CString  ipaddress;
 
 m_pSocket = new CSocketListen( this );
 
 if( m_pSocket )
 {
  //  Namensauflösung für Servernamen
  //
  m_ServerName.TrimLeft();
  m_ServerName.TrimRight();
 
  if( inet_addr( m_ServerName ) == INADDR_NONE )
  {
   HOSTENT *pHost = gethostbyname( m_ServerName );
   if( pHost )
    ipaddress.Format("%d.%d.%d.%d", (unsigned char)pHost->h_addr_list[0][0], 
                                    (unsigned char)pHost->h_addr_list[0][1], 
            (unsigned char)pHost->h_addr_list[0][2], 
            (unsigned char)pHost->h_addr_list[0][3] );
   else
    m_SocketStatus = WSAGetLastError();
  }
  else
   ipaddress.Format("%s", m_ServerName );
 
  //  Socket erzeugen
  //
  //if( m_pSocket->Create( m_ServerPort, SOCK_STREAM, ipaddress ) )
  if( m_pSocket->Create(m_ServerPort, SOCK_STREAM, ipaddress) )
  {
   m_pSocket->Listen();
   return true;
  }
  else
  {
   if( m_pSocket->Create( m_ServerPort, SOCK_STREAM, _T("127.0.0.1") ) )
   {
    m_pSocket->Listen();
    return true;
   }
   else
   {
    m_SocketStatus = GetLastError();
    return false;
   }
  }
 }
 else
 {
  MessageBoxMemory();
  return false;
 }
 ///////////////////////////////////////////////////////////////////////////
}


C# client code i used from this codeproject link

TCP/IP Chat Application Using C#[^]
[/edit[
Posted
Updated 12-Nov-11 6:59am
v3
Comments
LaxmikantYadav 10-Nov-11 4:45am    
Please post the error.
glued-to-code 10-Nov-11 4:49am    
Not able to connect to server
Andrew Brock 10-Nov-11 4:50am    
What methods are you using in C#?
A standard TCP/IP socket created with WinSock will not discriminate language.
Andrew Brock 10-Nov-11 5:46am    
By looking at the dataflow it seems that the C# library is sending additional parameters. The C++ server should recognise the connection (probably), but the c# client would not work. Try using the Socket class from http://msdn.microsoft.com/en-us/library/system.net.sockets.socket(v=vs.95).aspx
Richard MacCutchan 10-Nov-11 5:29am    
You may get a better response from the author of the article; post your question in the forum at the end of the article.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900