Posted By:
PhiDi_TranThi
Posted On:
Friday, November 8, 2002 10:51 AM
Hi, I wrote a client socket after I send: "and supposed to recieve: B vxmli I should received the following data (in 2 lines) Requested binding to service "vxmli" Server 10: BSVC vxmli 9 9 But all all I received is: Requested binding to service "vxm" How can I read the rest of the data (missing data) Following is my piece of code: import java.net.*; import java.io.*; public class tcpClient1 { public static void main(String[] args) { int port = 9000
More>>
Hi,
I wrote a client socket after I send:
"and supposed to recieve:
B vxmli
I should received the following data (in 2 lines)
Requested binding to service "vxmli"
Server 10: BSVC vxmli 9 9
But all all I received is:
Requested binding to service "vxm"
How can I read the rest of the data (missing data)
Following is my piece of code:
import java.net.*;
import java.io.*;
public class tcpClient1
{
public static void main(String[] args)
{
int port = 9000;
String servHost = "localhost";
Socket clSocket = null;
String stringToSend1 = "B vxmli";
String stringToSend2 = null;
String stringToSend3 = "E";
String inputLine,inputLine2, outputLine;
PrintWriter output = null;
BufferedReader input = null;
stringToSend2 = args[0];
try
{
System.out.println("connected with server");
clSocket = new Socket(servHost, port);
}
catch (SocketException socketE)
{
System.out.println("Create socket exception" + socketE.getMessage());
}
catch (IOException e)
{
System.out.println(e);
}
try
{
// Try to send first string to the other end of the socket
output = new PrintWriter(clSocket.getOutputStream(),true);
output.write(stringToSend1);
output.flush();
}
catch (IOException ioE1)
{
System.out.println(ioE1.getMessage());
}
try
{
input = new BufferedReader(new InputStreamReader(clSocket.getInputStream()));
}
catch (IOException ioE2)
{
System.out.println(ioE2.getMessage());
}
try
{
while ((inputLine = input.readLine()) != null)
{
System.out.println(inputLine);
output = new PrintWriter(clSocket.getOutputStream(),true);
output.write(stringToSend2);
}
}
catch (IOException ioE3)
{
System.out.println(ioE3.getMessage());
}
}
}
<<Less