|
The problem is on the PC end. Intel architecture's use a 'byte-swapped'
format for storing integers and other variables. In other words, they
store the bytes for an integer with the LSB first, and the MSB last.
However, the TCP/IP standard (as well as the AS/400 itself) do not use
this byte swapped format.
So, when your PC program does a 'sin_port = 3005' it won't work. (your
PC's representation of 3005 is different from the network's)
There should be C functions that can be used to convert these values. I
know that in UNIX versions of C, you'd do:
addr.sin_port = htons(3005);
But, I don't know what the proper function is in Windows (it may be the
same, I just don't know)
At any rate, it should get you on the right track.
On Mon, 23 Jul 2001, srichter wrote:
>
> Hello all,
>
> I am attempting to socket from a win95 pc to an as400. Both systems are on
>the same local ethernet lan. Both behind the firewall.
> When I run connect( ) on the pc, a "WSAECONNREFUSED" ( the attempt to connect
>was forcefully rejected ) error code is returned.
>
> My "Listen" pgm is running on the as400. It was able to rcv data on a
>loopback test, so I am reasonably sure it is coded correctly.
>
> Do I have to enable anything on the 400 or pc before socketing from one
>system to the other? Any ideas? Why the WSAECONNREFUSED error?
>
> Does the 400 log socket connection attempts that are refused?
>
> Thanks,
> Steve Richter
>
> Here is the code. First the c code on the pc, then the rpg ile as400 code.
>
> {
> SOCKET hSock;
> SOCKADDR_IN addr ;
> WSADATA wsaData ;
> int nRc ;
> CString sError ;
> WORD wWsaVer ;
>
> wWsaVer = MAKEWORD( 2, 2 ) ;
> nRc = WSAStartup( wWsaVer, &wsaData ) ;
>
> hSock = socket (AF_INET, SOCK_STREAM, 0) ;
> FillMemory( &addr, sizeof(addr), 0 ) ;
> addr.sin_family = AF_INET ;
> addr.sin_addr.s_addr = inet_addr( "172.xx.y.z" ) ;
> addr.sin_port = 3005 ;
> nRc = connect( hSock, (LPSOCKADDR)&addr, sizeof(addr) ) ;
> if ( nRc != 0 )
> {
> sError = subsGetSocketError( ) ;
> subsMessageBox( sError, "Socket Error" ) ;
> }
> nRc = WSACleanup( ) ;
> return ;
> }
>
> ** Create the socket.
> C Eval SD = Socket (AF_INET: SOCK_STREAM: 0 )
>
> ** If socket failed - End the server program with dump
> C If SD < 0
> C Eval rc = SockError('ServerSocket')
> c Goto EndPgm
> C EndIf
>
> ** Bind - set local address for the socket.
> C Eval SocketAddr = *ALLX'00'
> C Eval SinFamily = AF_INET
> C Eval SinPort = 3005
> C Eval SinAddr = INADDR_ANY
> C Eval rc = Bind (SD: %ADDR(SocketAddr)
> C : %SIZE(SocketAddr))
> C If rc < 0
> C Eval rc = SockError('ServerBind')
> c Goto EndPgm
> C EndIf
>
> ** Listen - Invite incoming connections.
> C Eval rc = Listen (SD: 1)
> C If rc < 0
> C Eval rc = SockError('ServerListen')
> c Goto EndPgm
> C EndIf
>
> ** Accept - Wait for connection request and Make connection.
> ** Accept incoming connection request from the client.
> ** A new socket (SD2) is created for the client.
> c Eval SD2 = Accept( SD:
> c %Addr(AccpAddr):
> c %Addr(AccpAddrLgth) )
> C If rc < 0
> C Eval rc = SockError('ServerAccept')
> c Goto EndPgm
> c EndIf
>
>
>
> +---
> | This is the Midrange System Mailing List!
> | To submit a new message, send your mail to MIDRANGE-L@midrange.com.
> | To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
> | To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com.
> | Questions should be directed to the list owner/operator: david@midrange.com
> +---
>
+---
| This is the Midrange System Mailing List!
| To submit a new message, send your mail to MIDRANGE-L@midrange.com.
| To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
| To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.