
-----------------------------------
SsJBebiGoku
Sat Mar 12, 2005 5:42 pm

SocketException Error
-----------------------------------
Hi,

When i try outputting something through a socket a second time the following error comes up:
java.net.SocketException: Software caused connection abort: socket write error

It appears at out.write() and/or out.flush() methods. I'm not sure why this is happening/how to fix it...

String line;
        //BufferedReader in = new SafeBufferedReader(new InputStreamReader(System.in));
        
        try
        {
            while(true)
            {
                line = chatWindow.getMessage();
                
                if(line != null)
                {
                   if(line.equals("exit"))
                   {
                        out.write("Your opponent is disconnecting by request.\r\n");
                        out.flush();
                        break;
                    }
                    out.write(playerName + ": " + line + "\r\n");
                    out.flush();
                  //  break;
                }
            }
        }
        catch(IOException e){e.printStackTrace();}

-----------------------------------
wtd
Sat Mar 12, 2005 6:41 pm


-----------------------------------
Can you show us your initialization of chatWindow?

-----------------------------------
rizzix
Sat Mar 12, 2005 8:04 pm


-----------------------------------
maybe the stuff sent is not recieved on the other end, considering the Socket is a wrapper over the TCP protocol. What is "out" anyways? If its a buffered writer (or similar classes) it should not be a problem, i think. I've lost touch in network programming.

-----------------------------------
SsJBebiGoku
Tue Mar 15, 2005 10:46 pm


-----------------------------------
Here's the whole "Output" class. it handles all the output sent from another computer. I've also posted the InputThread class as well that handles the input from the user and sends it out to another computer jsut for reference.

class InputThread extends Thread
{
    InputStream in;
    GameBoard board;
    ChatWindow chatWindow;
    ArrayList characters;
    
    /**constructor with 2 parameter
     *@param anInputStream the input stream of the computer
     *@param board the board object to alter
     *@param aChat the chat window to communicate through
     */
    public InputThread(InputStream anInputStream,GameBoard board,ChatWindow aChat)
    {
        chatWindow = aChat;
        in = anInputStream;
        this.board = board;
        characters = new ArrayList();
    }
    
    /**overriding method to activate the thread
     */
    public void run()
    {
        int[] coords = new int[2];
        int j;
        String output = "";
        try
        {
            output = "";
            characters.clear();
            for(int i = 0;;i++)
            {
                j = in.read();
                if(j == 10)//line feed
                    break;

                characters.add(new Character((char)j));
                break;
            }
            for(int i = 0;i