I'm trying to do socket programming for the first time, the client has sent a server which has been set up by operations, I need to access via socket program to call their APIs.
I'm trying to follow the instructions from this article
http://systeminetwork.com/article/introduction-tcpip-programming
And also referring to sample programs.
And using the /copy socket_h
My program is hanging up on the Reply. It sits there and hangs.
Ops has set up the new server in WRKSRVTBLE as:
Service Port Protocol
E0007825019-1 1200 tcp
The IP address of the new server is in the Host Table entries as E0007825019-01.
Getting the IP address works.
p_hostent = gethostbyname('E0007825019-01');
if (p_hostent = *NULL);
@preturn = 'CPCON01';
@prtnmsg = 'Host lookup failed. ';
joblog('Host lookup failed.');
return;
else;
addr = h_addr;
endif;
Getting the port works.
p_servent = getservbyname('E0007825019-1': 'tcp');
if (p_servent <> *NULL);
port = s_port;
else;
port = 1200;
endif;
Creating the socket works
s = socket(AF_INET: SOCK_STREAM: IPPROTO_TCP);
If (s = -1);
@preturn = 'CPCON02';
@prtnmsg = 'Socket failed. ';
joblog('Socket failed!');
return;
endif;
I connect to the server
connto = *ALLx'00';
connto.sin_family = AF_INET;
connto.sin_addr = addr;
connto.sin_port = port;
if ( connect(s: %addr(connto): %size(connto)) = -1 );
callp close(s);
@preturn = 'CPCON03';
@prtnmsg = 'Connect failed. ';
joblog('Connect failed!');
return;
endif;
Just to check the value, at one point I put this value into a variable:
connect(s: %addr(connto): %size(connto)
The value is 0.
It's certainly not -1, the error.
The program sits and hangs on the if statement:
if ( GetReply(s) <> 220 );
@preturn = 'CPCON04';
@prtnmsg = 'Server Not Ready ';
callp close(s);
joblog('Not ready for SMTP requests.');
return;
endif;
Any help I get will be greatly appriciated... If I need to provide more information please let me know.
I don't see anything in the job log pointing me to what's happening.
ALSO, by the way... Not sure if this has anything to do with my problem...
Is it unusual that, I connect using these commands,
Then the first thing the vendor wants me to do in their specs is to send them a CONNECT command?
Or is what they're requesting somehow supposed to be part of my connect?
They want me to connect by sending them a string like this:
'0000000022CONNECT|CLIENTTYPE|20|CLIENTID|222|'
I took that to mean, that once I'm connected (after my if statement) the next thing I do is this:
SendAscii(s: '0000000022CONNECT|CLIENTTYPE|20|CLIENTID|222|');
Does it make sense that I connect (to the server via socket) and then send them their bar-delimited connect command? It's like I'm connecting to connect...
Charlie
As an Amazon Associate we earn from qualifying purchases.