I'm trying to connect to java server socket placed on windows server from my computer.
I always got a timeout exception.
I have tried to disable firewall with no luck. it still gave me the same error.
Exception in thread "main" java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
server code
public class Server implements Runnable {
public static int PORT = 3425;
private ServerSocket server;
public Server() throws IOException{
server = new ServerSocket(PORT);
}
#Override
public void run() {
try {
System.out.println("Waiting for connection");
Socket socket = server.accept();
System.out.println("new socket attached " + socket.toString());
System.out.println("waiting for message to read it");
DataInputStream input = new DataInputStream(socket.getInputStream());
byte [] bytes = new byte[1000];
int text = input.read(bytes);
System.out.println("message received");
System.out.println(text);
System.out.println(Arrays.toString(bytes));
} catch (IOException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Client Code
public class Client implements Runnable {
Socket socket;
public Client() throws IOException {
System.out.println("trying to connect");
socket = new Socket("74.208.80.229", Server.PORT);
System.out.println("connected");
}
#Override
public void run() {
try {
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
Thread.sleep(1000);
System.out.println("message sent");
out.writeUTF("kasjdlkahdklajhdlkajsdhakljsdhlk");
out.flush();
} catch (IOException ex) {
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Related
This question already has answers here:
Official reasons for "Software caused connection abort: socket write error"
(14 answers)
Closed 7 years ago.
I'm trying to build a simple TCP multithreaded client/server application.
Whenever a Client (Socket) connects to the ServerSocket and send an Object (Message) that corresponds to the simple serializable class shown below, the server crashes when his ObjectInputStream tries to read from the client Socket getting a SocketExpection.
Message.java
package storageserver;
import java.io.Serializable;
public class Message implements Serializable {
private static final long serialVersionUID = 27015L;
public int ClientStatus; // 0 - NotLogged ::: 1 - Logged
public String Command;
public String[] Commands;
public Message()
{
this.ClientStatus = 0;
this.Command = null;
this.Commands = null;
}
public void createMessage(String msg)
{
this.Command = msg;
this.Commands = msg.split("\\s+");
}
}
StorageServer.java
package storageserver;
// imports..
public class StorageServer {
public static final int MAX_USERS = 250;
ServerSocket myServerSocket;
boolean serverOn = true;
File workingDir;
public StorageServer(int port, File dir) {
try {
InetAddress addr = InetAddress.getByName("192.168.1.73");
myServerSocket = new ServerSocket(port, MAX_USERS, addr);
workingDir = dir;
if(!workingDir.exists())
workingDir.mkdir();
System.out.println("StorageServer created successfully.");
} catch (IOException ex) {
Logger.getLogger(StorageServer.class.getName()).log(Level.SEVERE, null, ex);
System.out.println("Could not create storage server on port 7000. Exiting.");
System.exit(-1);
}
}
public void listen()
{
System.out.println("Listening for connections...");
while(serverOn)
{
try {
//accepts incoming TCP connection
Socket clientSocket = myServerSocket.accept();
//starts new service thread to handle client requests in background
new ClientHandleThread(clientSocket).start();
}
catch (IOException e)
{
System.out.println("Exception encountered on accept. Ignoring. Stack Trace :");
e.printStackTrace();
}
}
try {
myServerSocket.close();
} catch (IOException ex) {
Logger.getLogger(StorageServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
class ClientHandleThread extends Thread {
private Socket myClientSocket;
private HashMap<String, Runnable> commandsMap;
private Message messageToSend, messageToReceive;
public ClientHandleThread() {
super();
}
public ClientHandleThread(Socket myClientSocket) {
this.myClientSocket = myClientSocket;
this.messageToSend = new Message();
this.messageToReceive = new Message();
}
private void help()
{
messageToSend.createMessage("Avaible commands:\n\n"
+ "exit -> Exits the App\n"
+ "stop -> Stops the server\n"
+ "dir -> Gets personal file's info in current server\n");
messageToSend.ClientStatus = 0;
}
#Override
public void run()
{
ObjectInputStream in = null;
ObjectOutputStream out = null;
System.out.println("Accepted connection from "
+ myClientSocket.getInetAddress().getHostAddress()+ ":" + myClientSocket.getPort());
try
{
System.out.println("IN..");
in = new ObjectInputStream(myClientSocket.getInputStream());
out = new ObjectOutputStream(myClientSocket.getOutputStream());
System.out.println("IN!");
messageToReceive = (Message) in.readObject(); //exception here - Software caused connection abort: recv failed
System.out.println("Client Says :" + messageToReceive.Command);
out.writeObject(messageToSend);
out.flush();
} catch (IOException | ClassNotFoundException ex) {
ex.printStackTrace();
Logger.getLogger(StorageServer.class.getName()).log(Level.SEVERE, null, ex);
}
finally
{
try
{
in.close();
out.close();
myClientSocket.close();
System.out.println("...Stopped");
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
}
}
Debug output
java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.net.SocketInputStream.read(SocketInputStream.java:223)
at java.io.ObjectInputStream$PeekInputStream.peek(ObjectInputStream.java:2303)
at java.io.ObjectInputStream$BlockDataInputStream.peek(ObjectInputStream.java:2596)
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2606)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1319)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
at storageserver.StorageServer$ClientHandleThread.run(StorageServer.java:145)
nov 11, 2015 2:53:36 AM storageserver.StorageServer$ClientHandleThread run
What may be causing this exception ? I'm sure i do not close or reset the socket connection anywhere (client/server side).
EDIT:
Added client code below.
Client gets an exception when trying to receive() a response from the server.
TCPService.java (Client)
package client;
//imports..
public class TCPService {
private Socket clientSocket;
public TCPService(String host, int port)
{
try {
clientSocket = new Socket(InetAddress.getByName(host), port);
clientSocket.setSoTimeout(5000);
} catch (IOException ex) {
System.err.println("Cant connect to Storage Server.\n" + ex);
System.exit(-1);
}
}
public Message receive()
{
try {
ObjectInputStream in = new ObjectInputStream(clientSocket.getInputStream());
try {
Message msg = (Message) in.readObject();
if(msg instanceof Message)
return msg;
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
} catch (IOException ex) {
Logger.getLogger(TCPService.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
public void send(Message msg)
{
try {
ObjectOutputStream oos = new ObjectOutputStream(clientSocket.getOutputStream());
oos.writeObject(msg);
oos.flush();
oos.close();
} catch (IOException ex) {
Logger.getLogger(TCPService.class.getName()).log(Level.SEVERE, null, ex);
}
}
//Main
public static void main(String[] args) throws IOException
{
/* Service Variable Declaration */
TCPService tcpService = new TCPService(args[0], args[1]);
/* Other Variables */
String buf = "";
Scanner scanIn = new Scanner(System.in);
Message msg = new Message();
isTCPRunning = true;
/* While-Loop for TCP Service */
while (isTCPRunning)
{
System.out.print("[User#StorageServer] Insert command: ");
buf = scanIn.nextLine();
msg.createMessage(buf);
scanIn.reset();
tcpService.send(msg);
msg = tcpService.receive(); //SocketException -> Socket Closed
System.out.println("[StorageServer] " + msg.Command);
tcpService.handleMessage(msg);
}
}
Immediately upon sending a message, the client closes the ObjectOutputStream. This closes the socket's output stream, which closes the socket. By the time the client tries to read from the input stream, the socket is already closed, thus the exception on the client side. This may also be causing the problem on the server side, since by the time the server is reading data, the TCP connection may have been closed.
I have a client-server application. Right now, I'm trying to test sending messages from the client to the server and then read them from the server. I'm using ObjectInputStream and ObjectOutputStream to transfer message objects between the client and server.
However, when I try to write an object from the client, it results in a SocketException.
Server code:
while (true) {
try {
log.trace("Waiting for connection.");
Socket clientSocket = socket.accept();
log.trace("Socket connected");
/* create thread */
new Thread(new RequestRunner(clientSocket, serverID)).start();
} catch (SocketTimeoutException e) {
log.trace("Socket timed out.");
socket.close();
break;
} catch (IOException e) {
log.error("Cannot accept connection...");
break;
}
}
Server Thread:
public class RequestRunner implements Runnable {
....
public RequestRunner(Socket socket, UUID serverID) {
client = socket;
this.serverID = serverID;
}
/**
* Start the thread for the request
*/
public void run() {
log.trace("Thread started for socket");
try {
out = new ObjectOutputStream(client.getOutputStream());
in = new ObjectInputStream(client.getInputStream());
} catch (IOException e) {
log.error("Cannot intialize streams...");
return;
}
while(client.isConnected()) {
/* initialize streams */
try {
/* read message */
Object obj = in.readObject(); // does not block
MessageFrame msg = (MessageFrame) obj;
processRequest(msg);
} catch (IOException e) {
; // triggers everytime
//log.error("IO error occured while trying to get input/output stream from socket");
} catch (ClassNotFoundException e) {
log.error("Cannot read MessageFrame");
}
}
}
}
Client code:
public void init(int port) throws IOException {
log.trace("intializing to port " + port);
clientID = UUID.randomUUID();
socket = new Socket("0.0.0.0",port);
out = new ObjectOutputStream(socket.getOutputStream());
in = new ObjectInputStream(socket.getInputStream());
}
public void sendEcho() throws Exception {
while(socket.isConnected()) {
try {
log.trace("Sending echo..");
msg = new EchoMessage(clientID);
curMsgID = msg.getMsgID();
out.writeObject(msg); // throws SocketException, socket closed
out.flush();
break;
} catch (SocketException e) {
log.error ("Cannot send echo.. socket closed.");
break;
} catch (IOException e) {
continue;
}
}
}
The statement out.writeObject(msg) causes a ServerSocket exception with Socket closed as the reason. And the server does not register receiving an object from in.readObject().
netstat shows the connection as established, the error occurs when I try to write the object.
What am I doing wrong ?
You should only have one InputStream and one OutputStream.
out = new ObjectOutputStream(client.getOutputStream());
in = new ObjectInputStream(client.getInputStream());
Should be:
out = client.getOutputStream();
in = client.getInputStream()
And you should change it in the client code when getting the streams from the sockets as well.
I am working on Socket programming. I have build such a server which should accept multiple Clients. Here I have particular num of clients , clients keeps on sending msg to Server every 10sec , Server has to process it.The problem I am having is I am unable to connect multiple Server and here a single client is a continuous running programm in while(true) So if one client Sends a request another client can not connect . Here is my Program.
Server
public class SimpleServer extends Thread {
private ServerSocket serverSocket = null;
private Socket s1 = null;
SimpleServer() {
try {
serverSocket = new ServerSocket(1231);
this.start();
} catch (IOException ex) {
System.out.println("Exception on new ServerSocket: " + ex);
}
}
public void run() {
while (true) {
try {
System.out.println("Waiting for connect to client");
s1 = serverSocket.accept();
System.out.println("Connection received from " + s1.getInetAddress().getHostName());
InputStream s1In = s1.getInputStream();
DataInputStream dis = new DataInputStream(s1In);
String st = dis.readUTF();
System.out.println(st);
s1In.close();
dis.close();
s1.close();
// throw new ArithmeticException();
} catch (IOException ex) {
Logger.getLogger(SimpleServer.class.getName()).log(Level.SEVERE, null, ex);
}
catch (Exception e) {
System.out.println("Exceptiopn: "+e);
}
}
}
public static void main(String args[]) throws IOException {
new SimpleServer();
}
}
Server is working fine but I am not able to write Client program which shoud run in while(true) loop for sending msg to Server and allow other client also connect to Server.
but for a single client I write like this ,
public class SimClient extends Thread {
private Socket s1 = null;
SimClient() {
//this.start();
}
public void run() {
int i=0;
try {
s1 = new Socket("localhost", 1231);
} catch (IOException ex) {
Logger.getLogger(SimClient.class.getName()).log(Level.SEVERE, null, ex);
}
// while (i<10) {
try {
// Open your connection to a server, at port dfg1231
OutputStream s1out = s1.getOutputStream();
DataOutputStream dos = new DataOutputStream(s1out);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Data from Client:");
String s = br.readLine();
dos.writeUTF(s);
dos.flush();
s1out.close();
dos.close();
// s1.close();
i++;
} catch (IOException ex) {
//ex.printStackTrace();
System.out.println("Exception in While: "+ex.getMessage());
}
//}
}
public static void main(String args[]) throws IOException {
SimClient s= new SimClient();
s.start();
}
}
So can any one help me to write client program. its a great help for me.
just as you have a Thread for the ServerSocket, you need to create a Thread for every Socket returned by serverSocket.accept() , then it loops back around immediately to block and wait to accept another Socket. Make a class called SocketHander which extends Thread and accepts a Socket in the constructor.
public class SocketHandler extends Thread {
private Socket socket;
public SocketHandler(Socket socket) {
this.socket = socket;
}
public void run() {
// use the socket here
}
}
and back in the ServerSocket handler...
for (;;) {
SocketHandler socketHander = new SocketHandler(serverSocket.accept());
socketHander.start();
}
It is generally a good idea to use a Fixed Size Thread Pool because creating Threads in a ad-hoc manner may cause the Server to run out of Threads if the requests are high.
public class SimpleServer extends Thread {
private ServerSocket serverSocket = null;
private static ExecutorService executor = Executors.newFixedThreadPool(100);
SimpleServer() {
try {
serverSocket = new ServerSocket(1231);
this.start();
} catch (IOException ex) {
System.out.println("Exception on new ServerSocket: " + ex);
}
}
public void run() {
while (true) {
try {
System.out.println("Waiting for connect to client");
final Socket s1 = serverSocket.accept();
executor.execute(new Runnable() {
public void run() {
try {
System.out.println("Connection received from " + s1.getInetAddress().getHostName());
InputStream s1In = s1.getInputStream();
DataInputStream dis = new DataInputStream(s1In);
String st = dis.readUTF();
System.out.println(st);
s1In.close();
dis.close();
s1.close();
} catch(Exception e) {
System.out.println("Exceptiopn: "+e);
}
// throw new ArithmeticException();
}});
} catch (IOException ex) {
Logger.getLogger(SimpleServer.class.getName()).log(Level.SEVERE, null, ex);
} catch (Exception e) {
System.out.println("Exceptiopn: "+e);
}
}
}
public static void main(String args[]) throws IOException {
new SimpleServer();
}
}
I am new to google protocol buffer . I am writing a client server application where client send request object to server and server return response. Currently when i send object to server neither the server respond nor throw any exception. Probably it stuck on line
Request request = Request.parseFrom(bytes);
where Request and Response are my message classes generated by protocol buffer.
My code samples are as follows
public class TCPServer {
final static Logger logger = Logger.getLogger(TCPServer.class.getName());
static int PORT = 6789;
public static void main(String argv[]) throws Exception
{
ServerSocket socket = new ServerSocket(PORT);
Socket connectionSocket = null;
while(true)
{
try{
connectionSocket = socket.accept();
}catch (IOException e) {
System.out.println("Could not listen on port:" + PORT);
System.exit(-1);
}
Thread thread = new Thread(new ServerConnection(connectionSocket));
thread.start();
}
}
}
public class ServerConnection implements Runnable{
static final Logger logger = Logger.getLogger(ServerConnection.class.getName());
String clientInput;
String serverOutput = null;
Socket connectionSocket = null;
ServerConnection(Socket connectionSocket){
this.connectionSocket = connectionSocket;
}
public void run() {
try {
InputStream input = connectionSocket.getInputStream();
ObjectInputStream inFromClient = new ObjectInputStream(input);
ObjectOutputStream outToClient = new ObjectOutputStream(connectionSocket.getOutputStream());
serveRequest(inFromClient , outToClient);
outToClient.flush();
} catch (IOException ex) {
logger.log(Level.SEVERE, null, ex);
System.out.println("Exception occured in ServerConnection run() method");
}
}
public void serveRequest(InputStream inFromClient, OutputStream outToClient){
try {
System.out.println("Recieving data from client");
ResponseReciever response = new ResponseReciever();
ObjectInputStream input = (ObjectInputStream) inFromClient;
byte size = input.readByte();
byte []bytes = new byte[size];
input.readFully(bytes);
Request request = Request.parseFrom(bytes);
System.out.println("Request recieved");
response.createResponse(request.getId(),request.getMessage(),true).writeTo(outToClient);
System.out.println("Response send");
} catch (Exception ex) {
logger.log(Level.SEVERE, null, ex);
System.out.println("Exception occured in ServerConnection serverRequest() method");
}
}
And my client look like this
public class TCPClient {
final static Logger logger = Logger.getLogger(TCPClient.class.getName());
private static int PORT = 6789;
private static String HOST_NAME = "localhost";
private static boolean isOpen = true;
private Socket openConnection(final String hostName,final int port){
Socket clientSocket = null;
try {
clientSocket = new Socket(HOST_NAME, PORT);
} catch (IOException e) {
logger.log(Level.SEVERE, "Exception occured while connecting to server", e);
}
return clientSocket;
}
private void closeConnection(Socket clientSocket){
try {
logger.log(Level.INFO, "Closing the connection");
clientSocket.close();
isOpen = false;
} catch (IOException e) {
logger.log(Level.SEVERE, "Exception occured while closing the connection", e);
}
}
public void sendToServer(OutputStream output){
try {
System.out.println("Sending data to server");
RequestSender requestSender = new RequestSender();
Request request = requestSender.getRequest(1,"param1","param2",23L,"Its message",true);
ObjectOutputStream outputStream = (ObjectOutputStream)output;
request.writeTo(outputStream);
} catch (IOException ex) {
logger.log(Level.SEVERE, null, ex);
}
}
public void recieveFromServer(InputStream input){
try {
System.out.println("Recieving data from server");
Response response = Response.parseFrom(input);
System.out.println(response.getId());
System.out.println(response.getResponse());
System.out.println(response.getError());
} catch (IOException ex) {
logger.log(Level.SEVERE, null, ex);
}
}
public static void main(String argv[]) throws Exception
{
ObjectOutputStream outToServer = null;
InputStream inFromServer = null;
TCPClient client = new TCPClient();
try {
while(isOpen)
{
Socket clientSocket = client.openConnection(HOST_NAME, PORT);
outToServer = new ObjectOutputStream(clientSocket.getOutputStream());
inFromServer = new ObjectInputStream(clientSocket.getInputStream());
client.sendToServer(outToServer);
client.recieveFromServer(inFromServer);
}
}catch (Exception e) {
logger.log(Level.SEVERE, "Exception occured ", e);
System.out.println("Exception occured in TCPClient main() method");
System.exit(1);
}
}
}
I am unable to find what is wrong in the code. Please let me know if you find something missing.
It works by using writeDelimtedTo(outputStream) and parseDelimitedFrom(inputStream) instead of writeTo(outputStream) and parseFrom(inputStream). So by putting the following code on server and client sides the program works.
Server side:
InputStream input = connectionSocket.getInputStream();
OutputStream output = connectionSocket.getOutputStream();
Request request = null;
while ((request = Request.parseDelimitedFrom(input)) != null) {
System.out.println(request.toString());
}
Client side:
Socket clientSocket = client.openConnection(HOST_NAME, PORT);
Request request = getRequest();
OutputStream output = clientSocket.getOutputStream();
InputStream input = clientSocket.getInputStream();
request.writeDelimitedTo(output);
If you start sending protocol buffers over the wire - then you will need to "frame" them. The problem is reported and solved with this question: does protobuf need a network packet header?
Instead of writing all this code, you could checkout https://code.google.com/p/protobuf-rpc-pro/ and see if it satisfies your requirements for RPC between java server and java clients.
I have a problem with my Java program. It has a socket connection between a server and many client. Here is the server (the part which concerns the problem):
private static ArrayList<ParallelServer> clientConnected = new ArrayList<ParallelServer>();
public Server(int port) {
this.port = port;
if (!startServer())
JOptionPane.showMessageDialog(new JFrame(""),
"Error!", "ERROR!",
JOptionPane.ERROR_MESSAGE);
}
private boolean startServer() {
try {
server = new ServerSocket(port);
loadDatabase();
} catch (IOException ex) {
ex.printStackTrace();
return false;
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return true;
}
public void runServer() {
while (true) {
try {
client = server.accept();
ParallelServer pServer = new ParallelServer(client);
clientConnected.add(pServer);
Thread thread = new Thread(pServer);
thread.start();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
public static void sendBroadcast(String username) throws IOException {
for(int i = 0; i < clientConnected.size(); i++)
clientConnected.get(i).sendAnswer("#change," + username);
}
The parallel server is:
private Socket client;
private InputStreamReader inputstreamreader;
private BufferedReader bufferedreader;
private PrintWriter printwriter;
public ParallelServer(Socket client) {
this.client = client;
}
public void run() {
try {
inputstreamreader = new InputStreamReader(client.getInputStream());
bufferedreader = new BufferedReader(inputstreamreader);
printwriter = new PrintWriter(client.getOutputStream(), true);
String lineread = "";
while (client.isConnected()) {
lineread = bufferedreader.readLine();
doCommand(lineread);
}
} catch (UnknownHostException unhe) {
} catch (InterruptedIOException intioe) {
} catch (IOException ioe) {
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public void sendAnswer(String answer) throws IOException {
printwriter = new PrintWriter(client.getOutputStream(), true);
printwriter.println(answer);
printwriter.flush();
}
And here is the client:
private String serverurl = "localhost";
private int serverport = 7777;
private PrintWriter printwriter;
private InputStreamReader inputstreamreader;
private BufferedReader bufferedreader;
private Socket server;
public Client() {
server = null;
try {
server = new Socket(serverurl, serverport);
server.setSoTimeout(5000);
} catch (UnknownHostException unhe) {
System.out.println("UnknownHostException: " + unhe.getMessage());
} catch (InterruptedIOException intioe) {
System.out.println("Timeout while attempting to establish socket connection.");
} catch (IOException ioe) {
JOptionPane.showMessageDialog(new JFrame(),"Unable to reach the server!","ERROE!",JOptionPane.ERROR_MESSAGE);
}
}
public String sendCommand(String command) throws IOException {
if(server == null) {
try {
server = new Socket(serverurl, serverport);
server.setSoTimeout(5000);
} catch (UnknownHostException unhe) {
System.out.println("UnknownHostException: " + unhe.getMessage());
} catch (InterruptedIOException intioe) {
System.out.println("Timeout while attempting to establish socket connection.");
} catch (IOException ioe) {
JOptionPane.showMessageDialog(new JFrame(),"Unable to reach the server!","ERROR!",JOptionPane.ERROR_MESSAGE);
}
}
if(server != null) {
printwriter = new PrintWriter(server.getOutputStream(), true);
printwriter.println(command);
printwriter.flush();
inputstreamreader = new InputStreamReader(server.getInputStream());
bufferedreader = new BufferedReader(inputstreamreader);
return bufferedreader.readLine();
}
else
return "#serverProblem";
}
The program is a simple online game with turns. Players' turns are created with a queue and when a player passes his turn, the server send a broadcast message which say "Now it is 'Player 1' turn." (for instance). My problem is that when a client receive the message, its like it add the answer "Now it is 'Player 1' turn." to the next message it will receive. In my case: when a player passes his turn, he sends "#passTurn,username". The ParallelServer class polls it from the queue, puts it at the bottom of the queue, sends the client "#ok" to tell it that the turn has changed successfully and tells the Server class to send the broadcast message. Then, when the same client will try do do a further action, it will consider "Now it is 'Player 1' turn." as the answer the server has given to it. Instead, I would like that the server and the clients work as always and when the broadcast message is cought, the client is notified without any collateral effect.
What can I do?
Thanks.
Your bi-directional message passing mechanism should look something like this:
Server:
Wait on any client InputStream
if (broadcast)
broadcast_message()
else
process_message()
Client:
Receiving Thread:
Wait on server broadcast
Sending Thread:
Wait on messages to be sent to server from the User Input
This should do the trick :)
Hope it helps. Cheers!