Page 1 of 1

TCP/IP connection to .NET

Posted: Fri Nov 09, 2018 2:13 am
by rudzitis
Hi,

Is it possible for me to use TCP connection to call to .NET. I am setup a sample TCP IP server on .NET. Can someone tell me what I am doing wrong here?

I am trying to send message va CnTcpConnection but getting the following error:
2018/11/05 12:16:14.990: >>>>:AA/193: Error=31011 : Connection invalid state for requested operation : last action : Write
2018/11/05 12:16:14.990: >>>>:AA/193: Wrong connection state for cnOpen : state=1
2018/11/05 12:16:16.003: >>>>:AA/193: TCP error on connection #1 : client host was localhost on port 8888
2018/11/05 12:16:16.004: >>>>:AA/193: Error=31004 : Connection failed to connect : last action : Open


JADE CODE:

vars
vTCP : CnTcpConnection;
begin
app.initialize;
create vTCP transient;
vTCP.close;
vTCP.cnOpen('localhost',8888, vTCP);
vTCP.cnWrite('test'.Binary, vTCP);


.NET CODE

TcpListener serverSocket = new TcpListener(8888);
int requestCount = 0;
TcpClient clientSocket = default(TcpClient);
serverSocket.Start();
Console.WriteLine(" >> Server Started");
clientSocket = serverSocket.AcceptTcpClient();
Console.WriteLine(" >> Accept connection from client");
requestCount = 0;

Thaban

Re: TCP/IP connection to .NET

Posted: Fri Nov 09, 2018 6:54 am
by allistar
Use "netstat" in a command prompt to confirm that the .NET app is listening on the port. The command:

netstat -anop TCP

will show you all open TCP ports on the local computer and which process "owns" the connection. You should see any entry for port 8888 with a status of "LISTENING". If you don't then this is an issue with the .NET application. If you do then try and telnet to it:

telnet localhost 8888

If that opens a connection then the issue is most likely with the Jade code, if it doesn't then it's with .NET.

I personally would avoid the Cn class for this and instead use TcpIpConnection, at least until you can prove the connection works. Use non async calls to start with (as they're easier) and set a short time out (2 seconds). When using this in a real application it's better to use async calls as they're non blocking. Sync calls work as long as you use an exception handler to handle timeouts.

Hope this helps.

Re: TCP/IP connection to .NET

Posted: Fri Nov 09, 2018 7:49 am
by rudzitis
Thanks for your help.

I think the issue was the IP server. Even though I ran this on the thin client app, the system recognizes the 'localhost' as the server side. When I ran the .NET app on the server host, the localhost called worked.

Thaban

Re: TCP/IP connection to .NET

Posted: Fri Nov 09, 2018 8:22 am
by BeeJay
I think the issue was the IP server. Even though I ran this on the thin client app, the system recognizes the 'localhost' as the server side. When I ran the .NET app on the server host, the localhost called worked.
If you need this to open the port on the presentation client machine, check out the TcpIpConnection::usePresentationClient property.

Cheers,
BeeJay.