Titanium JIRA Archive
Appcelerator Community (AC)

[AC-2620] Data transmission via socket seems corruptted on latest SDK

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionInvalid
Resolution Date2014-02-04T05:36:02.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsapi, ios
ReporterDavid He
AssigneeRitu Agrawal
Created2014-01-22T03:46:00.000+0000
Updated2016-03-08T07:41:42.000+0000

Description

Steps to reproduce 1. Have a network printer configured with IP 192.168.20.175 and Port 9100 Make sure the computer where emulator running on and printer are both in the same network 2. Drop the attachment into project Documents folder 3. Run the code below using iOS 7.0.3 and Ti SDK 3.2.0

Test Code

var win = Ti.UI.createWindow({
	title : "Test Window"
});

var t = Ti.UI.createButton({
	title : "generate",
	bottom : 10,
	height : 40
});
win.add(t);

t.addEventListener("click", function(e) {
	var xData = psc();
	letsPrint(xData);
});

function psc() {
	try {
		var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "signature_bin.bin");
		// var sigBin = sigBlob;
		// //f.write("Signature: \n");
		// var bo = f.write(sigBin);
		var fileStream = f.open(Ti.Filesystem.MODE_READ);
		var buf = Ti.Stream.readAll(fileStream);
		return buf;
	} catch (e) {
		alert(e);
	}
}

function letsPrint(data) {
	var socket = Ti.Network.Socket.createTCP({
		host : '192.168.20.175',
		port : 9100,
		connected : function(e) {
			Ti.API.info('Socket opened!');
			Ti.Stream.pump(e.socket, readCallback, 1024, true);
			Ti.Stream.write(socket, data, writeCallback);
		},
		error : function(e) {
			Ti.API.info('Error (' + e.errorCode + '): ' + e.error);
		},
	});
	socket.connect();

	function writeCallback(e) {
		Ti.API.info('Successfully wrote to socket.');
	}

	function readCallback(e) {
		if (e.bytesProcessed == -1) {
		}
		try {
			if (e.buffer) {
				var received = e.buffer.toString();
				Ti.API.info('Received: ' + received);
			} else {
				Ti.API.error('Error: read callback called with no buffer!');
			}
		} catch (ex) {
			Ti.API.error(ex);
		}
	}
}

Expected Result

Signature printed out on docket

Actual Result

Nothing printed

{color:red}But the above code produces expected result on iOS 6.0 and Ti.SDK 2.1.4{color}

Attachments

FileDateSize
signature_bin.bin2014-01-22T03:46:00.000+000011994

Comments

  1. David He 2014-01-23

    Can anybody treat it urgently as our mobile product relies much on this and it cannot behave without the bug fix. Thanks
  2. Ritu Agrawal 2014-01-24

    [~jialhe85@gmail.com] It is tedious to diagnose this issue with network printer setup. Can you please try to reproduce this issue with a simple node based server instead of printer? It would also help us to narrow down the problem and expedite the problem diagnosis.
  3. David He 2014-01-29

    Hi Ritu After hours of investigations, I found that it seems like a problem with Model window in 3.2.0. I will re-produce the test code later. Thanks
  4. Ritu Agrawal 2014-01-31

    [~jialhe85@gmail.com] Did you get a chance to reproduce this problem with the model window?
  5. David He 2014-02-04

    Hi Ritu I am sorry that I could not reproduce this issue in model window. No idea why. Can you please close this ticket as invalid? Thanks
  6. Ritu Agrawal 2014-02-04

    Closing this ticket as invalid based on reporter's request.

JSON Source