GT.M SOCKET write question.

21 views
Skip to first unread message

kdt...@gmail.com

unread,
Nov 21, 2009, 5:38:42 PM11/21/09
to Hardhats
I have a question about socket write syntax. Specifically:

Write /listen(1)
Write /wait(timeout)


This was found in the example code in the GT.M programmer's manual in
the IO section (included at end of post).

These lines create a syntax error:

Write "Hello" /listen(1)
Write /listen(1) "Hello"

Write "Hello" /wait(timeout)
write /wait(timeout) "Hello"

So I understand that /LISTEN and /WAIT are control mnemonics, but the
manual is not clear about how to use them.

--Is this just a one time call that changes a parameter?
--The parameter of LISTEN is a "listen que depth". What does this
mean?

Thanks
Kevin

;server.m
Set portno=6321,delim=$c(13)
Set tcpdev="server$"_$j,timeout=30
Open
tcpdev:(ZLISTEN=portno_":TCP":attach="server"):timeout:"SOCK
ET"
Use tcpdev
Write /listen(1)
Write /wait(timeout)
;
;dialogue with the client
;
;client.m
Set host="orlando"
Set portno=6321
Set delim=$c(13)
Set tcpdev="client$"_$j,timeout=30
O
tcpdev:(connect=host_":"_portno_":TCP":attach="client"):time
out:"SOCKET"
Use tcpdev
;
;dialogue with the server
;

kdt...@gmail.com

unread,
Nov 22, 2009, 8:36:01 AM11/22/09
to Hardhats
OK.

I am using this line to open a SOCKET as a server.

SET PORT=+$GET(PORT)
SET TMGDELIM=$CHAR(13)
SET TMGTCPDEV="server$"_$JOB
SET TMGTIMEOUT=30
OPEN TMGTCPDEV:
(ZLISTEN=PORT_":TCP":DELIMITER=TMGDELIM:attach="server"):TMGTIMEOUT:"SOCKET"

This has worked at least once. I was able to send "#HELLO#" to the
client. But I can't can't get it to work further, and now it won't do
even that. Instead, I get an error of trying to use a device that
hasn't been opened.

I think the open is failing because the socket was still open from a
prior run. So I exit GT.M and run netstat, and the socket seems to
persist outside GT.M. I had been using port=9300.

kdt0p@poweredge:~$ netstat | grep 9300
tcp 309 0 localhost:9300 localhost:55387
CLOSE_WAIT
tcp 16 0 localhost:9300 localhost:39521
CLOSE_WAIT

So this is where I get in over my head. I don't have a good
understanding of sockets at the OS level.

What is netstat showing?
Are these processes that need to be killed?
Are they entries in a table that say what to do with incoming
signals?
How do I get them out of there?
What should I have done in GT.M to properly clear them out?

Thanks
Kevin

David Whitten

unread,
Nov 22, 2009, 9:48:13 AM11/22/09
to hard...@googlegroups.com
A write controlmnemonic must be used as if it were an argument to the WRITE command.

On Sat, Nov 21, 2009 at 4:38 PM, kdt...@gmail.com <kdt...@gmail.com> wrote:
I have a question about socket write syntax.  Specifically:

Write /listen(1)
Write /wait(timeout)


This was found in the example code in the GT.M programmer's manual in
the IO section (included at end of post).

These lines create a syntax error:

Write "Hello" /listen(1)

This is because /listen(1) isn't a command in MUMPS.
you meant to say:
    Write "Hello",/listen(1)
i.e. when you use a comma instead of a space, the /listen(1) is an argument to the WRITE
command instead of being the place of a command as far as MUMPS is concerned.
 
Write /listen(1) "Hello"

Similarly, "Hello" isn't a command, either. You wanted:
 Write /listen(1),"Hello"

Write "Hello" /wait(timeout)
write /wait(timeout) "Hello"


likewise:

Write "Hello",/wait(timeout)
write /wait(timeout),"Hello"

such a big difference that a comma makes in MUMPS...


So I understand that /LISTEN and /WAIT are control mnemonics, but the
manual is not clear about how to use them.

--Is this just a one time call that changes a parameter?
--The parameter of LISTEN is a "listen que depth".  What does this
mean?

Thanks
Kevin


I am not Bhaskar, but I expect that a listen queue depth is how many connections can wait until a connection is established to this listener on this port.

Best of Wishes
Dave

 
;server.m
Set portno=6321,delim=$c(13)
Set tcpdev="server$"_$j,timeout=30
Open
tcpdev:(ZLISTEN=portno_":TCP":attach="server"):timeout:"SOCK
ET"
Use tcpdev
Write /listen(1)
Write /wait(timeout)
;
;dialogue with the client
;
;client.m
Set host="orlando"
Set portno=6321
Set delim=$c(13)
Set tcpdev="client$"_$j,timeout=30
O
tcpdev:(connect=host_":"_portno_":TCP":attach="client"):time
out:"SOCKET"
Use tcpdev
;
;dialogue with the server
;

iq100

unread,
Nov 22, 2009, 11:09:45 AM11/22/09
to Hardhats
Hi Kevin,

I provided code that works between two Cache machines, in another
thread here on Hardhats.
You can also find that code, and documentation here:
http://vista.intersystems.com/csp/docbook/DocBook.UI.Page.cls?KEY=GIOD_interproccomm#GIOD_ipc_tcp

I would like to try GT.M but have not had time to do that yet.

I would suggest:
1. Baby steps ... write whether the open succeeds or not, on the
server side, and also on the client side. Use $T to test (I $T U 0 W
"Open succeeded ..... E U 0 W "Open failed".
2. Only after you know that the two $Ts succeed, before send/receive
traffic.
3. If the is a GT.M sample/example of working code, use it exactly as
written to see if it works the first time. Then make your changes.
4. Note that only the client side provides the TCP/IP address (of the
server), along with the port to use. The server side only needs to
specify a port number (noTCP/IP address is needed)
5. In Cache, Closing a device, frees the socket. Or just exit and
sign back on, if you think the socket is not freed by the OS. Putting
the $T test in you code should allow you to know for sure whether the
Opens succeeded or not.
6. Technically, in Cache at least, the client writes first to
establish/complete the connection. However my code and the sample code
in Cache, don't seem to require this.

Let us know what happens.
> > ;- Hide quoted text -
>
> - Show quoted text -

kdt...@gmail.com

unread,
Nov 22, 2009, 9:58:35 PM11/22/09
to Hardhats
Your advice is, of course, sound. Thanks for bringing me back to
reality. :-) . I went back to the example in the GT.M book, and
wrote a server and client routine as simply as possible. And it
worked!

I will say that the example code sets up a delimiter of $c(13), but
doesn't put it into the OPEN parameters. I added that, and it now
works more as expected.

I'll try to post back with progress. One baby step at a time... :-)

Thanks again.

Kevin

On Nov 22, 11:09 am, iq100 <PLe...@optonline.net> wrote:
> Hi Kevin,
>
> I provided code that works between two Cache machines, in another
> thread here on Hardhats.
> You can also find that code, and documentation here:http://vista.intersystems.com/csp/docbook/DocBook.UI.Page.cls?KEY=GIO...
Reply all
Reply to author
Forward
0 new messages