Created
February 24, 2015 05:36
-
-
Save px-amaac/06b313cde46fad4d2da9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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