Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19935] Windows: Implement Ti.Network.Socket.TCP

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2016-08-12T03:55:32.000+0000
Affected Version/sRelease 5.1.0
Fix Version/sRelease 6.1.0
ComponentsWindows
LabelsLiveView
ReporterKota Iguchi
AssigneeGary Mathews
Created2015-11-12T08:25:37.000+0000
Updated2017-01-20T22:59:49.000+0000

Description

Implement Ti.Network.Socket.TCP for Windows. http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Network.Socket.TCP NOTE: This is needed for LiveView *Test Case*
var socket = Ti.Network.Socket.createTCP({
    host: 'pastebin.com', port: 80,
    connected: function (e) {
        Ti.API.info('socket connected');

        // receive callback
        Ti.Stream.pump(e.socket, function (e) {
            alert(e.buffer.toString());
        }, 1024, true);

        // send GET request
        Ti.Stream.write(socket, Ti.createBuffer({
            value: 'GET /raw/eF5dK0xU HTTP/1.1\r\nHost: pastebin.com\r\nConnection: close\r\n\r\n'
        }), function (e) {
            Ti.API.info('socket sent GET');
        });
    }
});
socket.connect();

Attachments

FileDateSize
wp_ss_20170120_0002.png2017-01-20T22:57:56.000+0000134382

Comments

  1. Gary Mathews 2016-08-08

    master: https://github.com/appcelerator/titanium_mobile_windows/pull/807
  2. Sandro Lain 2016-11-15

    Hello I need to develop a Windows Phone app that performs communication via TCP socket. Specifically, it is an extension of an already developed apps for iOS and Android platforms with Titanium SDK. Seeing that the development of the TCP part is found only in the 6.1.0.x SDK version I have updated Appcelerator SDK and Studio to the latest versions. The TCP client implementation is present and working but I encountered some problems with sending messages, specifically it seems that the second message sent creates an error that crashes the application. I quote here the system information, the error log and test the application code. The TCP server is a simple nodejs echo script that responds with the message received. *Platform Info* OS: Windows 10 Pro Emulator: Mobile Emulator 10.0.14393.0 720p 5 inch 1GB Studio: 4.8.0.201611011053 appc 6.0.0-68 Titanium SDK 6.1.0.v20161113203131 *Studio Console Log* {noformat} -- Start application log ----------------------------------------------------- [INFO] [TEST] open connection [INFO] [TEST] connected [INFO] : Finished launching the application [INFO] [TEST] try to send [INFO] [TEST] sent [INFO] [TEST] received: 0 0 0 0 14 a0 [INFO] [TEST] try to send [ERROR] : ----- Titanium Javascript Runtime Error ----- [ERROR] : In undefined: undefined,undefined [ERROR] : Message: Uncaught Error: undefined [INFO] : Disconnected from app -- End application log ------------------------------------------------------- {noformat} *Test Code*
       
       var win = Ti.UI.createWindow();
       
       var lbl = Ti.UI.createLabel({
       	text: 'TCP Test'
       });
       win.add(lbl);
       
       win.addEventListener('open', function()
       {
       	var itv;
       	
       	var socket = Ti.Network.Socket.createTCP({
       		host: '192.168.1.88',
       	    port: 6262,
       	    timeout: 3000,
       	    connected: function(e)
       	    {
       	    	console.log("[TEST] connected");
       	    	
       	    	Ti.Stream.pump(e.socket, function(e)
       	    	{
       				if (e.bytesProcessed == -1)
       				{
       					// Socket :: END of received message
       			        return;
       			    }
       			    
       			    var res = [];
       			    
       			    for(var i = 0, len = e.buffer.length; i < len; i++)
       			    {
       			    	res.push(e.buffer[i].toString(16));
       			    }
       			    
       			    console.log("[TEST] received: " + res.join(" "));
       	    		
       	    	}, 1024, true);
       	    	
       	    	itv = setInterval(function()
       	    	{
       	    		if(!socket)
       	    		{
       	    			clearInterval(itv);
       	    			
       	    			return;
       	    		}
       	    		
       	    		var buff = Ti.createBuffer({
       					length: 6
       				});
       				
       				buff[0] = 0x00;
       				buff[1] = 0x00;
       				buff[2] = 0x00;
       				buff[3] = 0x00;
       				buff[4] = 0x14;
       				buff[5] = 0xA0;
       				
       				console.log("[TEST] try to send");
       				
       				Ti.Stream.write(socket, buff, function()
       				{
       					console.log('[TEST] sent');
       				});
       
       
       	    	}, 1000);
       	    },
       		error: function(e)
       		{
       			clearInterval(itv);
       			
       			socket = null;
       			
       			console.error("[TEST] socket error");
       			
       			console.error(e);
       		}
       	});
       	
       	console.log("[TEST] open connection");
       	
       	socket.connect();
       });
       
       win.open();
       
       
  3. Samir Mohammed 2017-01-20

    Verified feature with the test case provided by [~gmathews] in https://github.com/appcelerator/titanium_mobile_windows/pull/807. Screenshot shows the success message on the windows phone !wp_ss_20170120_0002.png|thumbnail! Code from the console:
       -- Start application log -----------------------------------------------------
       [INFO] :   socket connected
       [INFO] :   socket sent GET
       
    *Environment*
       Lumia 640 LTE (RM-1073) (OS Build 10.0.14393.693)
       Operating System
       Name                        = Microsoft Windows 10 Pro
       Version                     = 10.0.14393
       Architecture                = 64bit
       

    CPUs = 4

    Memory = 17034395648 Node.js Node.js Version = 4.4.4 npm Version = 2.11.3 Titanium SDK SDK Version = 6.1.0.v20170118152304

JSON Source