[java] tcp socket communication [send and recieve help]
- by raven
hello,
I am creating a Chat in java.
I have a method (onMouseRelease) inside an object
that creates a tcp server and waits for a socket
ServerSocket server = new ServerSocket(port);
Socket channel = server.accept();
now I want to make a thread that will loop and read data from the socket, so that once the user on the other side sent me a string, I will extract the data from the socket [or is it called packet? sry I am new to this], and update a textbox to add the additional string from the socket [or packet?].
I have no idea how to READ (extract) the information from the scoket [/packet] and then update it into a JTextArea which is called userOutput.
And how to Send a string to the other client, so that it will also could read the new data and update its JTextArea.
(from what I know, for a 2 sided tcp communication you need one computer to host a server
and the other to connect [as a client] and once the connection is set the client can also recieve new information from the socket. Is that true? and please tell me how )
Any help appreciated !! I know this is abit long but I have searched allot and didn't understand [I saw something like printwriter but failed to understand].