Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Previous section Next section Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Topic:
Network connections, how to read untill last character
This thread has 6 replies. Displaying all posts.
Post 1 made on Monday October 19, 2009 at 10:28
Janci
Lurking Member
Joined:
Posts:
October 2009
5
This code works and writes what I need. I have got problem with reading. Sometimes I need to read 9 characters and sometimes I need to read 11 character. When I change the number of character (for example 11) and are received only 9, it does not work. It is written some error.
var socket = new TCPSocket(true);
socket.connect('192.168.1.9', 1111, 3000);
socket.write(command);
//socket.read(number of character, time);
station = socket.read(9,300);
socket.close();
delete socket.onData;
delete socket.onClose;
delete socket.onConnect;
socket = null;
My question is, how to write code, which can read data with different number of character. Everytime is the last character 13. I want read data until I reach character 13. If it is possible could you write code?

Thank you very much
(sorry for my english)
Post 2 made on Monday October 19, 2009 at 15:24
Barry Gordon
Founding Member
Joined:
Posts:
August 2001
2,157
Use asynchronous communications, not synchronous. Read the developers guide.

Perform the read in the ondata event which fires with async communications when there is input data. Accumulate the data read on successive invocations data+=socket.read(). While the data buffer contains a CR Char 13), remove all the chars in the data buffer up to and including the CR as that is what you want and process them as the message. Leave what was in the buffer after the CR (if there was anything) as the start of the next message. When the data buffer contains no CR, exit the ondata function

Last edited by Barry Gordon on October 26, 2009 14:36.
OP | Post 3 made on Monday October 19, 2009 at 17:12
Janci
Lurking Member
Joined:
Posts:
October 2009
5
I used this code and it does not work. I think that I have no connection, because I do not write anything, and I do not read anything as well.


var socket = new TCPSocket(false);
var station = "";
socket.onConnect = function()
{
write("command);
};
socket.onData = function()
{
station += read();
};
socket.connect('192.168.1.9', 1111, 3000);

What am I doing wrong? I am totally hopeless. Any idea?

Thank you
Post 4 made on Monday October 19, 2009 at 19:23
Barry Gordon
Founding Member
Joined:
Posts:
August 2001
2,157
Go to my web site (www.the-gordons.net) and download the documents on TCPIP communications. They have code examples and might help you.

If what you have written is accurate you have a syntax error in the write command (missing close quote).

Also you might try replacing read() with socket.read() and write with socket.write("command"). In the context of the call back it should not be necessary but I deal with so many different languages that I just fully qualify everything so I don't have to remember all the nuances
OP | Post 5 made on Monday October 26, 2009 at 02:31
Janci
Lurking Member
Joined:
Posts:
October 2009
5
How can I find if there is in asynchronous communications a connection? When I had synchronous communication and there was not connection, I could see in my debug page error connection, but when I u se debug page in asynchronous there is nothing.

Thank you
Post 6 made on Monday October 26, 2009 at 06:29
Sogliphy
Long Time Member
Joined:
Posts:
July 2007
186
On October 26, 2009 at 02:31, Janci said...
How can I find if there is in asynchronous communications a connection? When I had synchronous communication and there was not connection, I could see in my debug page error connection, but when I u se debug page in asynchronous there is nothing.

Something like:

var s = new TCPSocket(false);
s.onConnect = function () {
System.print("Yippie! I got a connection!");
};
s.onIOError = function (e) {
System.print("Oh no, something went wrong: " + e);
};
s.onClose = function () {
System.print("The connection got closed");
};
s.onData = function () {
var data = this.read();
System.print("Received " + data.length + " bytes of data");
};
s.connect("192.168.1.101", 80, 6000); // edited to add 2nd param of port 80

Last edited by Lyndel McGee (moderator) on October 26, 2009 21:53.
Post 7 was deleted by a forum moderator.


Jump to


Protected Feature Before you can reply to a message...
You must first register for a Remote Central user account - it's fast and free! Or, if you already have an account, please login now.

Please read the following: Unsolicited commercial advertisements are absolutely not permitted on this forum. Other private buy & sell messages should be posted to our Marketplace. For information on how to advertise your service or product click here. Remote Central reserves the right to remove or modify any post that is deemed inappropriate.

Hosting Services by ipHouse