2 Replies - 815 Views - Last Post: 24 November 2012 - 10:19 PM Rate Topic: -----

#1 iSpectrum  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 15-April 12

[Question] Java chat program

Posted 24 November 2012 - 02:07 PM

Hi, everyone! I`m (beginner by the way)coding some chat program in java. I know i need to use Thread in there but i don't where to insert it in. Here is my code. I would appreciate any help :bigsmile:/> . This is a server.class
import java.io.*;
import java.net.*;
import java.util.*;
//
public class Server {
	@SuppressWarnings("resource")
	public static void main(String[] args) throws IOException {
		String msg=null;
		Scanner scan=new Scanner(System.in);
		System.out.print("Port: ");
		int port=scan.nextInt();
		ServerSocket server=new ServerSocket(port);
		System.out.println("Listening on port: " + port);
		Socket socket=server.accept();
		System.out.println("Connection from: " + socket.getLocalAddress().getHostAddress());
		while(true){
		PrintWriter out=new PrintWriter(socket.getOutputStream(),true);
		msg=scan.nextLine();
		out.println(msg);
		out.flush();
		System.out.println("Server: " + msg);
		
		}
	}
}


Is This A Good Question/Topic? 0
  • +

Replies To: [Question] Java chat program

#2 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 822
  • View blog
  • Posts: 2,529
  • Joined: 29-July 11

Re: [Question] Java chat program

Posted 24 November 2012 - 04:17 PM

There's a chat application tutorial in the Java tutorials section that covers everything nicely.
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: [Question] Java chat program

Posted 24 November 2012 - 10:19 PM

farrell2k I am afraid your friend iSpectrum would need quite a basic but really basic tutorial

http://www.dreaminco...snippet1917.htm

then he can go on more complicated stuff like a chat room :)

http://www.dreaminco...r-gui-optional/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1