Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session Stream over Text-Net #1

Open
php5developer opened this issue Jun 27, 2017 · 3 comments
Open

Session Stream over Text-Net #1

php5developer opened this issue Jun 27, 2017 · 3 comments

Comments

@php5developer
Copy link

Can you explain what does this line mean? Thank you
session.on('end', () => session.end());

@dongmuni-rankwave
Copy link
Collaborator

dongmuni-rankwave commented Jun 27, 2017

Like TCP, The 'session' is a bidirectional messaging.
In order to gracefully terminate a connection in TCP, both parties must send and receive FIN packet.
The 'session' is likewise bidirectional messaging, you must send and receive messages with the 'F' flag to gracefully terminate.
Otherwise, the 'client' object may determine that there is a message to send, and the internally managed 'session' object may become garbage.

@php5developer
Copy link
Author

php5developer commented Jun 28, 2017

Thank you for your answer. I thought in the same way, but after some tests I realised that I do not receive response from the server i.e. on client side the session event "end" doesn't fire. Here is my sample code.
Client

let imgName = 'sample.jpg';
let filename = path.resolve(__dirname, imgName);
let frs = fs.createReadStream(filename);
let session = client.createSession('FILE', [imgName]);
session.on('end', () => console.log('Image has been uploaded'));
frs.pipe(session);

Server

client.onSession('FILE', (session) => {
    let filename = path.resolve(__dirname, `client_${session.session_args[0]}`);
    let fws = fs.createWriteStream(filename);
    session.on('end', () => {
        console.log(`${session.session_args[0]} has been saved`);
        session.end();
    });
    session.pipe(fws);
});

So I see in console: "sample.jpg has been saved", but I don't see message "Image has been uploaded". Let me know please if I'm doing something wrong. By the way, your library is super good, cause it's lightweight and don't use a lot of dependencies like other similar ones.

P.S. Node version is 8.1.2

@dongmuni-rankwave
Copy link
Collaborator

Sorry. I have been busy with the project in recent weeks and will respond to it now.
I checked recently and found that the final version of the nodejs-text-net package is not registered in the npm registry.
Github has ver. 0.1.4, and npm regsitry has ver. 0.1.3 registered.
I guess I forgot to publish the final version.
It will be good if you try again. I apologize for the inconvenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants