Quote:var app = require('http').createServer(handler) , io = require('socket.io').listen(app) , fs = require('fs') app.listen(8070); var mysocket = 0; function handler (req, res) { fs.readFile(__dirname + '/index.html', function (err, data) { if (err) { res.writeHead(500); return res.end('Error loading index.html'); } res.writeHead(200); res.end(data); }); } io.sockets.on('connection', function (socket) { socket.send('hi'); console.log('index.html connected'); mysocket = socket; }); //udp server on 41181 var dgram = require("dgram"); var server = dgram.createSocket("udp4"); server.on("message", function (msg, rinfo) { console.log("msg: " + msg); if (mysocket != 0){ mysocket.emit('field', ""+msg); } }); server.on("listening", function () { var address = server.address(); console.log("udp server listening " + address.address + ":" + address.port); }); server.bind(41181);
Quote:socket.send('hi');
Quote:public static void RecieveUDP(int count) { Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); socket.Connect("127.0.0.1", 41181); byte[] bytes = new byte[256]; // length of the text "Hello world!" // receive data with timeout 10s for (int x = 0; x < count; x++) { Console.WriteLine(socket.Receive(bytes)); } socket.Close(); }
socket.Connect("127.0.0.1", 8888);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)