From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,962210d2c0d87c61,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newshub.sdsu.edu!tethys.csu.net!nntp.csufresno.edu!sn-xit-02!sn-xit-09!sn-xit-08!sn-xit-01!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "mla154" Newsgroups: comp.lang.ada Subject: Winsock using Aonix ObjectAda - client/server Date: Tue, 31 Aug 2004 16:31:20 -0400 Organization: www.talkaboutprogramming.com Message-ID: X-Newsreader: www.talkaboutprogramming.com Content-Type: text/plain; X-Complaints-To: abuse@supernews.com Xref: g2news1.google.com comp.lang.ada:3230 Date: 2004-08-31T16:31:20-04:00 List-Id: My goal is to convert C code to Ada code of a client/server application. The Ada compiler I need to use to write the code is Aonix ObjectAda version 7.2 Enterprise Edition for Windows NT. The client code for C works properly: #include #include int main() { DWORD e; WSADATA ws; int sockfd; int len; struct sockaddr_in address; int result; char ch = 'A'; /* Create a socket for the client. */ e=WSAStartup(0x0101,&ws); sockfd = socket(AF_INET, SOCK_STREAM, 0); /* Name the socket, as agreed with the server. */ address.sin_family = AF_INET; address.sin_addr.s_addr = inet_addr("127.0.0.1"); address.sin_port = htons(53); len = sizeof(address); /* Now connect our socket to the server's socket.*/ result = connect(sockfd, (struct sockaddr *) &address, len); if(result == -1) { perror("oops: client3"); exit(1); } /* We can now read/write via sockfd. */ send(sockfd, &ch, 1, 0); recv(sockfd, &ch, 1, 0); printf("char from server = %c\n", ch); closesocket(sockfd); exit(0); } I came up with the following Ada code (does not compile without errors): with Ada.Text_Io; with Ada.Unchecked_Conversion; with Win32; with Win32.Winsock; procedure Client is type Pcch is access constant Win32.Char; type String9 is new String(1..9); package Tio renames Ada.Text_Io; package Ws renames Win32.Winsock; function Sai_To_Sa is new Ada.Unchecked_Conversion( Ws.Sockaddr_In, Ws.Sockaddr); function String9_To_Pcstr is new Ada.Unchecked_Conversion(String9, Win32.Pcstr); function Ul_To_Sa1T is new Ada.Unchecked_Conversion(Ws.U_Long, Ws.Struct_Anonymous1_T); Ch : aliased Win32.Char := 'A'; Could_Not_Connect : exception; Ch_Access : Pcch; E, L1, Len, Result : Win32.INT; Ws1 : Ws.LPWSADATA := new Ws.WSADATA; Address : Ws.Sockaddr_In; Sockfd : Ws.SOCKET; begin Ch_Access := Ch'access; E := Ws.Wsastartup(16#0101#, Ws1); Sockfd := Ws.Socket_Func(Ws.AF_INET, Ws.SOCK_STREAM, 0); Address.Sin_Family := Ws.AF_INET; Address.Sin_Addr.S_Un.S_Un_B := (127,0,0,1); Address.Sin_Port := Ws.Htons(53); Address.Sin_Zero := (others => Win32.Nul); Len := Win32.INT(Address'Size); Result := Ws.Connect(Sockfd, new Ws.Sockaddr'(Sai_To_Sa(Address)), Len); if Integer(Result)=-1 then Tio.Put_Line("error: connect"); raise Could_Not_Connect; end if; L1 := Ws.Send(Sockfd, Win32.Pcstr(Ch_Access), 1, 0); L1 := Ws.Recv(Sockfd, Win32.Pstr(Ch_Access), 1, 0); Tio.Put_Line("char from server = "&Character(Ch)); L1 := Ws.Closesocket(Sockfd); exception when others => null; end Client; The compiler error I've been seeing is regarding the second parameter of the ws.send function. I need to choose something different for the second parameter (I think). All help is appreciated.