Created
August 27, 2013 16:21
-
-
Save tomgullo/6355737 to your computer and use it in GitHub Desktop.
Java sockets test
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
/* | |
//client | |
import java.io.* | |
import java.net.* | |
def sentence = 'i am testing this' | |
def clientSocket = new Socket("localhost", 6789) | |
try { | |
(new DataOutputStream( | |
clientSocket.getOutputStream() | |
)).writeBytes(sentence + '\n') //write text to socket | |
def returnVal = | |
(new BufferedReader | |
(new InputStreamReader( | |
clientSocket.getInputStream() | |
))).readLine() //read response | |
println returnVal | |
} catch(Exception ex) { | |
println 'error ' + ex | |
} | |
clientSocket.close() | |
*/ | |
import java.io.* | |
import java.net.* | |
def welcomeSocket = new ServerSocket(6789) | |
while(true) { | |
def connectionSocket = welcomeSocket.accept() | |
println 'accepted connection' | |
def inputVal = | |
(new BufferedReader( | |
new InputStreamReader( | |
connectionSocket.getInputStream() | |
))).readLine() | |
(new DataOutputStream( | |
connectionSocket.getOutputStream() | |
)).writeBytes( inputVal.toUpperCase() + '\n' ) | |
println 'done processing loop' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment