I am having a pretty rough time testing. I'm testing a server socket and this is the code I have to test
Code snippet of class containing server socket:
PrintWriter pout = null;
String spotNumber = "";
try {
InputStream in = theSocket.getInputStream();
OutputStream out = theSocket.getOutputStream();
Scanner scan = new Scanner(in);
pout = new PrintWriter(out, true);
spotNumber = scan.nextLine();
System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
System.out.println(spotNumber);
System.out.println(spotNumber);
} catch(Exception ex)
{
... other not important stuff
}
Code snippet of class creating client socket to test server socket:
String security = "security";
try {
Socket socket = new Socket("localhost", 3738);
if(socket.isConnected())
{
DataOutputStream writer = new DataOutputStream(socket.getOutputStream());
writer.writeBytes(security);
writer.flush();
}
}catch(Exception ex) {
ex.printStackTrace();
}
The client socket connects to the server socket, but it's not reading "security". What am I doing wrong with sending the data over the socket?
Aucun commentaire:
Enregistrer un commentaire