Results 1 to 2 of 2
  1. #1
    JavaJimme is offline Member
    Join Date
    Nov 2012
    Posts
    30
    Rep Power
    0

    Default Chatclient - write msg to IRC server

    Hello,

    I'm new on this forum so I will do a small introduction, I'm Jimme van der Meer, I'm from Holland, studying software engineering and I'm looking for abit of help on this app.

    I want to make a simple chat client to put on my website as an Applet that is using IRC protocols.
    The connection is established and I'm in the IRC server>channel but I can't figure out how to send messages to the server.

    Now the first question is: I've read about the printwriter to send messages but is that necessary when I got a BufferedWriter already?
    Second question: I know that I'll have to add threads to this app, I know how they work for the most part, but first I want to test if I'm able to send a message to the server, I hope this is possible without threads?
    Last but not least: I'm able to write messages to my own computer as local server but to IRC seems tickier, so how the hell do I send a message to the IRC sever?

    Here's the start of my source code, I'll hope somebody is able to help.
    Thanks in advance Jimme

    Java Code:
    import java.awt.FlowLayout;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.io.PrintWriter;
    import java.net.Socket;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.ScrollPaneConstants;
    
    
    public class IRCclient {
    
    	String nick = "";
    	
    	
    	JFrame frame;
    	JTextArea chatwindow;
    	JTextField sendwindow;
    	
    	Socket socket;
    	BufferedWriter bw;
    	BufferedReader br;
    	PrintWriter pw;
    	
    	public void createGui(){
    		
    		frame = new JFrame();
    		frame.setLayout(new FlowLayout());
    		JPanel panel = new JPanel();
    		sendwindow = new JTextField(30);
    		
    		panel.setLayout(new GridBagLayout());
    		GridBagConstraints gbc = new GridBagConstraints();
    		
    		chatwindow = new JTextArea(30,30);
    		
    		JScrollPane scroller = new JScrollPane(chatwindow);
    		scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    		panel.add(scroller);
    		
    		sendwindow.addActionListener(new ChatWindowActionListener());
    		gbc.gridx = 0;
    		gbc.gridy=1;
    		gbc.insets=new Insets(
    							  5, //hoogte
    							  0, //naar rechts
    							  0, //hoogte?
    							  0 //naar links
    							  );
    		panel.add(sendwindow, gbc);
    		
    
    		frame.add(panel);
    		frame.setSize(500,650);
    		frame.setVisible(true);
    		frame.setLocationRelativeTo(null);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		
    		
    	}
    	
    	
    	
    	private void IRCconnection(){
    		try{
    			socket = new Socket("holmes.freenode.net", 6667);
    			System.out.println("connection established"); 		
    		
    			bw = new BufferedWriter(new OutputStreamWriter( socket.getOutputStream())); 
    			
    			br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    			
    			bw.write ("NICK test12 \n\r");
    			bw.write ("USER test12 hpxn.net holmes.freenode.net :HPXN IRC TEST\n\r" );
    			bw.write ("JOIN #hpxntest\n\r");
    			bw.flush();
    			String currLine = null;
    
    			while ( (currLine = br.readLine()) != null ) {
    			  chatwindow.append(currLine);
    			  chatwindow.append("\n"); //nextline
    			  chatwindow.setCaretPosition(chatwindow.getText().length()); //autoscroll down
    			}
    			
    		}catch(IOException ex){
    			ex.printStackTrace();
    		}
    		
    	}
    	
    	
    	public class ChatWindowActionListener implements ActionListener{
    		@Override
    		public void actionPerformed(ActionEvent g) {
    			try{
    				//code????
    			}catch(Exception ex){
    				ex.printStackTrace();
    			}
    		
    		}
    	}
    	
    	
    	
    	public static void main(String[] args) {
    		IRCclient client = new IRCclient();
    		client.createGui();
    		client.IRCconnection();
    	}
    }
    I tried googling it and I've read the book head first java but there are not enough examples on how to write a message to an IRC server
    Last edited by JavaJimme; 11-15-2013 at 11:02 PM.

  2. #2
    JavaJimme is offline Member
    Join Date
    Nov 2012
    Posts
    30
    Rep Power
    0

    Default Re: Chatclient - write msg to IRC server

    sorry for dubble post this one can be deleted :|

Similar Threads

  1. Write Log File On Server Side
    By sdkrp in forum Advanced Java
    Replies: 4
    Last Post: 09-12-2013, 02:48 PM
  2. Easiest Way to Write to File on a Server?
    By atomant in forum New To Java
    Replies: 11
    Last Post: 04-29-2012, 12:48 PM
  3. applet can't write file in web server??
    By rajula in forum Java Applets
    Replies: 1
    Last Post: 05-02-2011, 02:48 PM
  4. How to write two server program in java
    By priyamurugar in forum Networking
    Replies: 1
    Last Post: 04-27-2010, 11:20 AM
  5. Applet Server Write Permission
    By Look2Logic in forum New To Java
    Replies: 0
    Last Post: 04-13-2010, 09:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •