When you talk over a socket under program control, there is no concept of 'record'; all you have is a stream of bytes. They arrive in order but at unpredictable times. You may do sdselect to see if there are bytes to read; then you may read them. It is up to your protocol to handle the case where the bytes come in one at a time, 1024 at a time, or some mix in between.

When the peer closes the connection, you will notified by sdselect that there is data to read, but when you read, you will get 0 bytes. This signals a closed connection.

Henry Rich

On 1/27/2013 8:28 PM, bill lam wrote:
The keyword you missed is stress.  Run some jobs to comsume nearly
all of the network bandwidth.  This is not specific to J, but it
is the way how socket programming works in general.

Вс., 27 янв. 2013, Bob Miller писал(а):
In jconsole(line by line) it works just fine, i cannot see why it should fail in script 
mode(when executing "jconsole file").
Can you suggest how can experiment with it?


Line by line xecution:
-----------------------------------
localhost: jconsole
    load 'socket'
    coinsert 'jsocket'
    ]socket =: 0 pick sdcheck sdsocket ''
4
    ]jsoft =: sdcheck sdgethostbyname 'www.jsoftware.com'
┌─┬───────────┐
│2│23.21.67.48│
└─┴───────────┘
    ]sdcheck sdconnect socket ; jsoft , < 80

    ]sdcheck ('GET /',CR,LF) sdsend socket,0
┌─┐
│7│
└─┘
    data =: ;sdcheck sdrecv socket , 10000000 , 0
    #data
5121
    sdcheck sdclose socket
-----------------------------------

Script execution:
-----------------------------------
localhost: cat test.ijs
load 'socket'
coinsert 'jsocket'

socket =: 0 pick sdcheck sdsocket ''
jsoft =: sdcheck sdgethostbyname 'www.jsoftware.com'
sdcheck sdconnect socket ; jsoft , < 80
sdcheck ('GET /',CR,LF) sdsend socket,0
data =: ;sdcheck sdrecv socket , 10000000 , 0
sdcheck sdclose socket

localhost: jconsole test.ijs
    #data
1448
-----------------------------------
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to