|
-
Oct 29th, 2005, 09:39 AM
#1
Thread Starter
Addicted Member
socket listning
Hello folks,
I made this "function" to listen for data from a visualbasic app.
Code:
public static void ListenConnection(int port)
try
{
ServerSocket ss=new ServerSocket(port);
Socket sa=ss.accept();
System.out.println("Client Accepted");
}catch(Exception e){System.out.println(e);}
I got a problem printing out the data is just received, do i need to make some sort of a declare of the socket?
Code:
// BufferedReader br=new BufferedReader(new InputStreamReader(sa.getInputStream()));
// System.out.println(br.readLine());
Thanks,
Nait
-
Oct 29th, 2005, 05:26 PM
#2
Frenzied Member
Re: socket listning
What do you mean a problem? Are you recieving an error? How are you sending data?(with a printwriter?)
The only thing I can think of is you are not reading everything, except for one line:
Code:
String inputLine;
while ((inputLine = br.readLine()) != null)
{
System.out.println(inputLine + "\n");
}
Maybe that's it?
-
Oct 31st, 2005, 10:42 AM
#3
Thread Starter
Addicted Member
Re: socket listning
Hi again,
All i want is to get all received data printed in the java-consol.
But if i use "catch(Exception" it will only print out "java.lang.NullPointerException" in the consol.
I don't know much about java, but must i close the socket each time it accepted new data?
Code:
private Socket sa;
public static void ListenConnection(int port)
{
try
{
ServerSocket ss=new ServerSocket(port);
Socket sa=ss.accept();
System.out.println("Client Accepted");
//BufferedReader sa=new BufferedReader(new InputStreamReader(sb.getInputStream()));
}catch(Exception e){System.out.println(e);}}
Code:
try
{
BufferedReader br=new BufferedReader(new InputStreamReader(sa.getInputStream()));
String inputLine;
while ((inputLine =br.readLine()) != null)
{
System.out.println(inputLine + "\n");
}
}catch(Exception e){System.out.println(e);}
Thanks,
Naitsabes
Last edited by naitsabes85; Oct 31st, 2005 at 10:45 AM.
-
Oct 31st, 2005, 03:48 PM
#4
Frenzied Member
Re: socket listning
Where is the code that sends the data? You've got code listening and taking in what was sent, but I need to see how you send the data. As for closing it, you don't need to close it, but you can try to flush() the stream which is probably a good idea.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|