1.公司业务有一个需求是,本地调用条码秤,并修改条码秤内商品价格
业务代码如下:
//客户端代码 app.js
var net = require('net');
var HOST = '172.16.0.67'; //服务器的ipv4地址
var PORT = 3001;
var data=`<Message>
<ARTSCommonHeader MessageType="Request"/>
<ItemTransaction ActionCode="Update"><Item>
<PLU>3</PLU>
<DepartmentID>0</DepartmentID>
<AlternativeItemIDs Action="Create">
<AlternativeItemID>2</AlternativeItemID>
</AlternativeItemIDs>
<Descriptions Action="Create">
<Description Type="ItemName">折价蔬菜22</Description>
<Description ID="0" Type="ExtraText"/>
<Description Type="ShortPinYinCode" Index="1"></Description>
</Descriptions>
<ItemPrices Action="Update">
<ItemPrice ValueTypeCode="BasePrice" Index="0" UnitOfMeasureCode="KGM" PriceOverrideFlag="false" DiscountFlag="false" Hidden="false">199.00</ItemPrice>
</ItemPrices>
<Dates Action="Create">
<DateOffset Type="PackedDate" UnitOfOffset="day" IsPrintEnabled="true">0</DateOffset>
<DateOffset Type="SellBy" UnitOfOffset="day" IsPrintEnabled="true">0</DateOffset>
</Dates>
<LabelFormats Action="Create">
<LabelFormatID Index="0">0</LabelFormatID>
</LabelFormats>
</Item></ItemTransaction>
var client = new net.Socket();
client.connect(PORT, HOST, function(e) {
console.log('CONNECTED TO: ' + HOST + ':' + PORT);
// 建立连接后立即向服务器发送数据,服务器将收到这些数据
client.write(data);
});
// 为客户端添加“data”事件处理函数
// data是服务器发回的数据
client.on('data', function(data) {
console.log('established: ' +
client.remoteAddress + ' ' + client.remotePort);
console.log('DATA: ' + data);
// 完全关闭连接
client.destroy();
});
// 为客户端添加“close”事件处理函数
client.on('close', function() {
console.log('Connection closed');
});
//直接node app.js 即可修改条码秤价格
;
### 问题根源 ###
其实核心问题比较直接,就是浏览器如何调用node 的net模块
尝试过Browserify 打包net模块,但不生效,输出是空对象
链接如下:[Browserify 打包uniq模块][1]
没有找到可行方案,望各位同仁不吝赐教...交流学习