Results 1 to 2 of 2
- 04-09-2009, 06:31 PM #1
Member
- Join Date
- Apr 2009
- Posts
- 1
- Rep Power
- 0
Receiving Text over a Socket (ReadLine() problem)
Hi there! I have been struggling for several days now to resolve an issue I am having with a game I am designing. Basically I am using sockets to make my game run over the internet, and despite it working, I am have issues with the ReadLine() on my client.
I the Game returns 1 line of text to the client, it is fine. If I try and return multiple lines of text, such as..
out.println("Hello there!" + "\n how are you?";
it will only read the first line (Hello There). I have tried looping the Realine() method until it reaches null, and this works. However, when I send the next command to the server, the ReadLine method won't return anything, almost as though its "stopped". I have tried resetting it, looping it, but it just isn't working.
Not asking anyone to write this for me, just asking if anyone could help point me in the right direction or explain what's going wrong. Any help is greatly appreciated!
Below is my Client
import java.io.*;
import java.net.*;
public class Client {
public static void main(String[] args) throws IOException {
Socket mySocket = null;
PrintWriter out = null;
BufferedReader in = null;
try {
mySocket = new Socket("86.7.165.118",4450);
out = new PrintWriter(mySocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(mySocket.getInputStream()));
} catch (UnknownHostException e) {
System.err.println("Can't find the Host");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for the connection to the IP");
System.exit(1);
}
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
String userInput;
while ((userInput = stdIn.readLine()) != null) {
out.println(userInput); //Send data to server
System.out.println(in.readLine()); //Print data received from server
}
}
}
- 04-09-2009, 10:35 PM #2
Similar Threads
-
[SOLVED] problem in socket connection
By neeraj.singh in forum NetworkingReplies: 2Last Post: 02-20-2009, 01:33 PM -
problem in socket connection in sending images
By vibhor in forum NetworkingReplies: 2Last Post: 02-20-2009, 05:39 AM -
Hi there, and i have little problem with readLine
By Chesh in forum New To JavaReplies: 10Last Post: 01-17-2009, 08:30 PM -
problem with console.readLine()
By thatguy in forum New To JavaReplies: 1Last Post: 12-14-2008, 07:40 PM -
Client Server socket problem - help needed
By kellaw in forum Threads and SynchronizationReplies: 6Last Post: 10-03-2008, 06:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks