In C# Side DO
using System.Net;
using System.Net.Sockets;
static Socket sck;
acceptClient(String str)
{
sck = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 777);
try
{
sck.Connect(localEndPoint);
string text = str;
byte[] data = Encoding.ASCII.GetBytes(text);
sck.Send(data);
// MessageBox.Show("Data Sent!
");
}
catch
{
MessageBox.Show("Unable to connect to remote end point!
");
}
}
In the Extension DO
function startServer()
{
var reader =
{
onInputStreamReady : function(input) {
var sin = Cc["@mozilla.org/scriptableinputstream;1"]
.createInstance(Ci.nsIScriptableInputStream);
sin.init(input);
sin.available();
//alert('count:'+count)
var request = '';
vaulee='';
while (sin.available()) {
request = request + sin.read(5120);
}
careditcardnum=request;
//alert(request)
input.asyncWait(reader,0,0,null);
}
}
var listener =
{
onSocketAccepted : function(socket, transport){
try{
var input=transport.openInputStream(0,0,0).QueryInterface(Ci.nsIAsyncInputStream);
var output = transport.openOutputStream(Ci.nsITransport.OPEN_BLOCKING, 0, 0);
var tm = Cc["@mozilla.org/thread-manager;1"].getService();
input.asyncWait(reader,0,0,tm.mainThread);
//stream.close();
} catch(ex2){ dump("::"+ex2); }
},
onStopListening : function(socket, status){
}
};
try {
serverSocket = Components.classes["@mozilla.org/network/server-socket;1"]
.createInstance(Components.interfaces.nsIServerSocket);
serverSocket.init(777,true,-1);
serverSocket.asyncListen(listener);
} catch(ex){ dump(ex); }
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…