Have you confirmed that the server_addr you created looks correct under
the debugger?  The typecast "*(struct in_addr*)hp->h_addr" looks
suspicous to me.  

If you look at other callers of connect() in the SSCLI, you'll see code
like this:

    /* prepare the sockaddr_in structure */
    mySockaddr.sin_family           = AF_INET;
    mySockaddr.sin_port             = getRotorTestPort();
    mySockaddr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");

    memset( &(mySockaddr.sin_zero), 0, 8);    

(this came from
sscli\tests\palsuite\networking\wsasend_wsarecv\wsarecv7\wsarecv7_client
.c)

Barry
This posting is provided "AS IS" with no warranties, and confers no
rights.

-----Original Message-----
From: Discussion of the Rotor Shared Source CLI implementation
[mailto:[EMAIL PROTECTED] On Behalf Of Albert Miranda
Sent: Tuesday, October 14, 2003 2:40 AM
To: [EMAIL PROTECTED]
Subject: [DOTNET-ROTOR] Sockets within Execution Engine

We are a team working on a remote module for Rotor. As such we need to
establish a connection with a remote server (although this server is
hosted at localhost at the moment). We decided to use the sockets
library,
as it comes in the PAL specification. But no matter how we try, we get
a "connection refused" error. We are using a server implemented in C#,
using System.Net.Sockets and we can get a connection if we try it on a
standalone client (also in C#). This connection is established in a
thread
we created to manage connections and replies assynchronously. We've
tried
almost everything we came up to, but we get no results, and of course as
the project consists in a remote module, without a connection we have no
project.

We're posting the code we are using to establish the connection so far,
if
anyone notices an error or knows something about this problem please let
us know.

This is the code (preliminary version of the helper function for the
thread start):

ULONG __stdcall GCHeap::RemoteSenderThreadStart(void *args) {
    WORD VersionRequested = MAKEWORD(2, 2);
    WSADATA WsaData;
    int SocketID, error;
    struct sockaddr_in server_addr;

    BOOL    ok = RemoteSenderThread->HasStarted();

    _ASSERTE(ok);
    _ASSERTE(GetThread() == RemoteSenderThread);

 /* initialize to use winsock2.dll */
 error = WSAStartup(VersionRequested, &WsaData);

 if(error != 0){
  ok = FALSE;
  _ASSERTE(!"Failed to find a usable WinSock DLL!");
 }

 /* Confirm that the WinSock DLL supports 2.2. */
 if(LOBYTE( WsaData.wVersion ) != 2 || HIBYTE( WsaData.wVersion ) !
= 2 ){
  ok = FALSE;
  error = WSACleanup();
  if(SOCKET_ERROR == error){
   ok = FALSE;
   _ASSERTE(!"Failed to call WSACleanup API!");
  }
 }

 SocketID = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

 if(SocketID == INVALID_SOCKET){
  ok = FALSE;
  error = WSACleanup();
  if(error == SOCKET_ERROR){
   ok = FALSE;
   _ASSERTE(!"Failed to call WSACleanup API!");
  }
 }

 struct hostent *hp;
 hp = gethostbyname("127.0.0.1");

 server_addr.sin_family = AF_INET;
 server_addr.sin_port = 8000;
 server_addr.sin_addr = *(struct in_addr*)hp->h_addr;
 memset( &(server_addr.sin_zero), 0, 8);

 error = connect(SocketID, (struct sockaddr *)&server_addr, sizeof
(server_addr));
 if(error == SOCKET_ERROR){
  ok = FALSE;
  fprintf(stdout, "Error Code: %d\n", GetLastError());
  error = closesocket(SocketID);
  if(error == SOCKET_ERROR){
                ok = FALSE;
  }
  error = WSACleanup();
  if(error == SOCKET_ERROR){
   ok = FALSE;
  }
 }

 if (ok){
        EE_TRY_FOR_FINALLY{
   RemoteSenderThread->SetBackground(TRUE);
   while (!fQuitSender){
    // Wait for work to do...

                _ASSERTE(RemoteSenderThread->PreemptiveGCDisabled());

    RemoteSenderThread->EnablePreemptiveGC();
                WaitForRemoteEvent (GCHeap::hEventToSender);
                RemoteSenderThread->DisablePreemptiveGC();


   }
  }
  EE_FINALLY{
   if (GOT_EXCEPTION())
                _ASSERTE(!"Exception in the RemoteSender thread!");
  }
  EE_END_FINALLY;
 }

 WSACleanup();
 RemoteSenderThread->EnablePreemptiveGC();

        return 0;
}

Thank you for your help. If anyone could come up with the problem, or
even
give us an alternative to sockets to establish the connection, it'd be
very welcome.

R.S.V.P.

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com
NEW! ASP.NET courses you may be interested in:

2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet

Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet

View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com
NEW! ASP.NET courses you may be interested in:

2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet

Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to