Skip to content

Instantly share code, notes, and snippets.

@px-amaac
Created February 24, 2015 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save px-amaac/06b313cde46fad4d2da9 to your computer and use it in GitHub Desktop.
Save px-amaac/06b313cde46fad4d2da9 to your computer and use it in GitHub Desktop.
var net = require('net');
var HOST = '127.0.0.1';
var PORT = 4242;
var server = net.createServer();
server.listen(PORT, HOST);
server.on('connection', function(sock) {
console.log('CONNECTED');
sock.on('data', function(data) {
console.log(data);
});
sock.on('close', function(data) {
console.log('CLOSED');
});
});
try {
InetAddress serverAddress = InetAddress.getByName("192.168.0.1");
Socket socket = new Socket(serverAddress, 4242);
connected = true;
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
socket.getOutputStream())), true);
out.println("heyDude");
socket.close();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
@px-amaac
Copy link
Author

So I am new to nodejs and i am attempting to open a socket connection using the code from this gist. https://gist.github.com/px-amaac/06b313cde46fad4d2da9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment