Applet socket problem in client-server, urgent!

Dear All:
I have implemented a client server teamwork environment. I have managered to get the server running fine. The server is responsible for passing messages between clients and accessing Oracle database using JDBC. The client is a Java Applet. The code is like the following. The problem is when I try to register the client, the socket connection get java.security.AccessControlException: access denied(java.net.SocketPermission mugca.its.monash.edu.
au resolve)
However, I have written a Java application with the same socket connection method to connect to the same server, it connects to the server without any problem. Is it because of the applet security problem? How should I solve it? Very appreciate for any ideas.
public class User extends java.applet.Applet implements ActionListener, ItemListener
public void init()
Authentication auth = new Authentication((Frame)anchorpoint);
if(auth.getConnectionStreams() != null) {
ConnectionStreams server_conn = auth.getConnectionStreams();
// Authenticates the user and establishes a connection to the server
class Authentication extends Dialog implements ActionListener, KeyListener {
// Object holding information relevant to the server connection
ConnectionStreams server_conn;
final static int port = 6012;
// Authenticates the user and establishes connection to the server
public Authentication(Frame parent) {
// call the class Dialog's constructor
super(parent, "User Authentication", true);
setLocation(parent.getSize().width/3, parent.getSize().height/2);
setupDialog();
// sets up the components of the dialog box
private void setupDialog() {
// create and set the layout manager
//Create a username text field here
//Create a password text field here
//Create a OK button here
public void actionPerformed(ActionEvent e) {
authenticateUser();
dispose();
// returns the ConnectionStreams object
public ConnectionStreams getConnectionStreams() {
return(server_conn);
// authenticates the user
private void authenticateUser() {
Socket socket;
InetAddress address;
try {
// open socket to server
System.out.println("Ready to connect to server on: " + port);
socket = new Socket("mugca.its.monash.edu.au", port);
address = socket.getInetAddress();
System.out.println("The hostname,address,hostaddress,localhost is:" + address.getHostName() + ";\n" +
address.getAddress() + ";\n" +
address.getHostAddress() + ";\n" +
address.getLocalHost());
catch(Exception e) {
displayMessage("Error occured. See console");
System.err.println(e);
                              e.printStackTrace();
}

Hi, there:
Thanks for the help. But I don't have to configure the security policy. Instead, inspired by a message in this forum, I simply upload the applet to the HTTP server (mugca.its.monash.edu.au) where my won server is running. Then the applet is download from the server and running fine in my local machine.
Dengsheng

Similar Messages

  • Authetication problem in client/server app

    I am presently developing a client/server program, and I'm wondering what will be the best form of authentication. I plan to develop a protocol for the programs, any deviation leading to socket closure. I thought about signatures, but I don't think any body's ready to vouch for me(ie I don't know how to go about signatures). Is there any help?

    Learn about JAAS

  • Large file transfer problems over client/server socket

    Hi,
    I wrote a simple chat problem in which I can send files from client to client. The problem is when I send large files over 101 MB the transfer freezes. I do not even get any error mesages in the console. The files I am sending are of any type (Ex mp3, movies, etc...). I am serializing the data into a "byteArray[packetSize]" and sending the file packet by packet until the whole file has been sent, and reconstructed on the other side. The process works perfectly for files smaller than 101MB, but for some reason freezes after that if the file is larger. I have read many forums and there aren't too many solutions out there. I made sure to use the .reset() method to reset my ObjectOutputStream each time I write to it.
    Here's my file sending code:
    byte[] byteArray = new byte[defaultPacketSize];
    numPacketsRequired = Math.ceil(fileSize / defaultPacketSize);
    try {
    int i = 0;
    reader = new FileInputStream(filePath);
    while (reader.available() > 0) {
    if (reader.available() < defaultPacketSize) {
    byte[] lastPacket = new byte[reader.available()];
    reader.read(lastPacket);
    try {
    if (socket == null || output == null) {
    throw new SocketException("socket does not exist");
    output.writeObject(lastPacket);
    output.reset();
    output.writeObject("DONE");
    output.reset();
    output.close();
    socket.close();
    catch (Exception e) {
    System.out.println("Exception ***: " + e);
    output.close();
    socket.close();
    else {
    reader.read(byteArray);
    try {
    if (socket == null || output == null) {
    throw new SocketException("socket does not exist");
    output.writeObject(byteArray);
    output.reset();
    catch (Exception e) {
    System.out.println("Exception ***: " + e);
    output.close();
    socket.close();
    reader.close();
    catch (Exception e) {
    System.out.println("COULD NOT READ PACKET");
    Here's my file receiving code:
    try {
    // The message from the client
    Object streamInput;
    FileOutputStream writer;
    byte[] packet;
    while (true) {
    streamInput = input.readObject();
    if (streamInput instanceof byte[]) {
    packet = (byte[]) streamInput;
    try {
    writer = new FileOutputStream(outputPath, true);
    writer.write(packet); //Storing the bytes on file
    writer.close();
    catch (Exception e) {
    System.out.println("Exception: " + e);
    else if (streamInput.equals("DONE")) {
    socket.close();
    input.close();
    break;
    catch (Exception e) {
    I'm looking for any way I can possibly send large files from client to client without having it freeze. Are there any better file transfer ways other than socket? I don't really want FTP. I think I want to keep it HTTP.
    Any suggestions would be helpful.Thanks!
    Evan

    I've taken a better look a the code you posted, and
    there is one problem with the receiving code. You
    keep repeatedly opening and closing the
    FileOutputStream. This is not going to be efficient
    as the file will keep needing to be positioned to its
    end.Yes sorry I did change that code so that it leaves the file open until completely done writing. Basically I have a progress bar that records how far along in the writing process the client is, and when the progress bar reaches 100%, meaning the file is complete, the file.close() method is invoked. Sorry about that.
    I also ran some memory tests using the "Runtime.getRuntime().totalMemory()", and "Runtime.getRuntime().freeMemory()" methods. I put these methods inside the loop where I read in the file and send it to the client. here's the output:
    Sender's free memory: 704672
    File reader read 51200 bytes of data.
    767548 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 702968
    File reader read 51200 bytes of data.
    716348 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 701264
    File reader read 51200 bytes of data.
    665148 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 699560
    File reader read 51200 bytes of data.
    613948 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 697856
    File reader read 51200 bytes of data.
    562748 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 696152
    File reader read 51200 bytes of data.
    511548 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 694448
    File reader read 51200 bytes of data.
    460348 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 692744
    File reader read 51200 bytes of data.
    409148 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 691040
    File reader read 51200 bytes of data.
    357948 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 689336
    File reader read 51200 bytes of data.
    306748 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 687632
    File reader read 51200 bytes of data.
    255548 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 685928
    File reader read 51200 bytes of data.
    204348 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 684224
    File reader read 51200 bytes of data.
    153148 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 682520
    File reader read 51200 bytes of data.
    101948 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 680816
    File reader read 51200 bytes of data.
    50748 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 679112
    File reader read 50748 bytes of data.
    0 left to read.
    Creating last packet of size: 50748
    Last packet size after setting it equal to byteArray: 50748
    Here's the memory stats from the receiver:
    Receiver's free memory: 639856
    Receiver's total memory: 2842624
    Receiver's free memory: 638920
    Receiver's total memory: 2842624
    Receiver's free memory: 637984
    Receiver's total memory: 2842624
    Receiver's free memory: 637048
    Receiver's total memory: 2842624
    Receiver's free memory: 636112
    Receiver's total memory: 2842624
    Receiver's free memory: 635176
    Receiver's total memory: 2842624
    Receiver's free memory: 634240
    Receiver's total memory: 2842624
    Receiver's free memory: 633304
    Receiver's total memory: 2842624
    Receiver's free memory: 632368
    Receiver's total memory: 2842624
    Receiver's free memory: 631432
    Receiver's total memory: 2842624
    Receiver's free memory: 630496
    Receiver's total memory: 2842624
    Receiver's free memory: 629560
    Receiver's total memory: 2842624
    Receiver's free memory: 628624
    Receiver's total memory: 2842624
    Receiver's free memory: 627688
    Receiver's total memory: 2842624
    Receiver's free memory: 626752
    Receiver's total memory: 2842624
    Receiver's free memory: 625816
    Receiver's total memory: 2842624
    Receiver's free memory: 624880
    Receiver's total memory: 2842624
    Receiver's free memory: 623944
    Receiver's total memory: 2842624
    Receiver's free memory: 623008
    Receiver's total memory: 2842624
    Receiver's free memory: 622072
    Receiver's total memory: 2842624
    Receiver's free memory: 621136
    Receiver's total memory: 2842624
    Receiver's free memory: 620200
    Receiver's total memory: 2842624
    Receiver's free memory: 619264
    Receiver's total memory: 2842624
    Receiver's free memory: 618328
    Receiver's total memory: 2842624
    Receiver's free memory: 617392
    Receiver's total memory: 2842624
    Receiver's free memory: 616456
    Receiver's total memory: 2842624
    Receiver's free memory: 615520
    Receiver's total memory: 2842624
    Receiver's free memory: 614584
    this is just a sample of both receiver and sender's stats. Everything appears to be fine! Hope this message post isn't too long.
    Thanks!

  • Servlet/applet/socket problem

    Hi there,
    my problem is this...
    i create a page with an servlet whicht shows an applet. this applet connects to a server through an socket. it works fine, but, when i change the page and the applet is not longer on the screen, the socket connection will be not killed! i dont know why. but i must kill it when the applet is not longer on the screen...whats wrong? can you help me?
    matthias

    Are you overriding the destroy() method in your Applet? This will be called when the applet is about to be unloaded from the browser. Or, as a slightly different alternative, you can override the stop() method, which is called when the applet is scrolled off the screen. Usually when stop() is used, start() is overriden as well to allow the applet to resume when it is scrolled back into view. For more info, read up on the applet lifecycle.

  • Problem with client\ server program

    hello,
    i have two programs one client and the other is server but i can't connect between client and server
    how can i connect between client and server ??
    this programs run in jbuilder

    what type of client u r using.WHich server u r using to run u r programs.If u r client and server is simple java client then u can use Socket to client to server.Otherwise u can use jsp/servlet to connect to the app /web server comm'n
    Anand

  • Applet & socket problem

    I want to request Socket port (23)and exchange string from Applet program
    When I try this program , java security exception occur
    how I can use port 23 from Applet
    thanks

    you either have to sign your applet or change you java.policy file to allow the applet to use the socket. to edit the policy file you can use policytool or a text editor.
    more info can be found at http://java.sun.com/docs/books/tutorial/security1.2/summary/tools.html

  • How to run a Applet program in a client/server way

    I have a Applet program, i use the Archive Builder in JBuilder5 to pack my program, then i install the jre1.4 in my windows 2000 . I also configure the Web server successfully. But when i open a browser, it can download the Applet,but it can not find the other classes which are uesd in my program. The browser i used is IE5.0 .
    Thank you!

    check ur archive properties in Applet tag,add it in your html document, such as
    <applet name="applet1" code="urApplet.class" codebase="[your applet relative path of html document on server]" archive="dt.jar,tools.jar"></applet>

  • Problem with Access Server (Urgent)

    Hi everyone.
    From 1 month ago, I receive an error in my Event log manager :
    Source ----------------- Facility ----------------- Severity ----------------- Message
    local7 ----------------- --local7 ----------------- -debug ----------------- Error getting session id
    In AS5350 this log recorded :
    Feb 18 10:25:10 Error getting session id
    This AS used for connecting to the gas station and transfer information to the main DB.
    AS use ACS for users who need to log in and also use ACS for dial out to gas stations.
    Does anyone know what is it?
    Please help me.
    Thanks a lot.

    Post Author: Dipesh
    CA Forum: WebIntelligence Reporting
    Check your have the correct java version, it needs to be less than version 1.6

  • Chat Applet - Sockets - Server

    Hello Fellows!
    I hope u all r fine..
    I am facing a problem in my client/sever application. The communication is Socket Based. i.e the server is using sockets and the client which is an Applet, uses sockets to communicate with the sever.
    The application is working fine in the appletviewer. i.e the applet server communication, both can send and recieve messages.
    BUT
    When I use IE5 the client applet can send messages to the sever but is not able to read from the specified socket...
    If Any one can help me out, i will be greatfull. If u need some code segment then let me know.
    Looking forward for any suggestions.
    Thanking You!
    Ahmad.

    Thanks!
    for your contribution....
    but now i realised that the problem is that the client socket thread is not running.
    //////////////////////// Client Applet
    public class Client extends Applet implements ActionListener
    Thread thRead;
    ClientSocket cs;
    private Panel pnlHead = new Panel();
    private Panel pnlMain = new Panel();
    public static Vector vtrMembers;
    public void init()
    thRead = (Thread) new ClientSocket();
         cs = (ClientSocket) thRead;
         vtrMembers = new Vector();
    thRead.start();     
    cs.out.println("INI ? INI");
    ////////////////////////////////////////Client scoket class
    public class ClientSocket extends Thread
    // public static Socket sClient;
    public Socket sClient;
    // A character-input stream to read from the socket.
    public static BufferedReader in;
    // A text-output stream to write to the socket.
    public PrintWriter out ;
    // String to store the input from the client
    String strText;
    // Boolean Flag to Check the read value
    public boolean bFlag = true;
    public ClientSocket ()
         try
         sClient = new Socket ("Ahmed" , 4000);
         // Initializing the Input straem used to read the socket.
    in = new BufferedReader(new InputStreamReader(sClient.getInputStream()));
         // Initializing the Output straem used to write on the socket.
         out = new PrintWriter(sClient.getOutputStream(), true);
         catch (UnknownHostException uhe)
    //     System.out.println (" Unknown Host Exception : " + uhe);
         catch (IOException ioe)
    //     System.out.println (" I/O Exception : " + ioe);
    public void run()
         for (;;)
         if (bFlag == true)
         Client.txtTry.setText("TRUE");
         else
         Client.txtTry.setText("False");
    thRead.start() statment is executed but the thread does not stat running
    because the text value is not set on the Client Applet.

  • How to get started on java applet client/server game?

    Hi,
    I've googled, but didn't find any useful information about creating java applet client/server game. I've followed the example of Client/Server Tic-Tac-Toe Using a Multithreaded Server in Java How to Program from Deitel, but I when I tried on Applet, my cliet doesn't communicate with the server at all. Any help to get started with Applet would be great. Thanks!

    well, i decided to put in portion of my codes to see if anyone can help me out. the problem I have here is the function excute() never gets called. here is my coding, see if you can help. Notice, I'm running this on Applet thru html page. This shouldn't be much different than running JFrame in term of coding right?
    Server.java
        public void init()
            runGame = Executors.newFixedThreadPool(2);
            gameLock = new ReentrantLock();
            otherPlayerConnected = gameLock.newCondition();
            otherPlayerTurn = gameLock.newCondition();
            players = new Player[2];
            currentPlayer = Player1;
            try
                server = new ServerSocket(12345, 2);
            catch (IOException ie)
                stop();
            message = "Server awaiting connections";
        public void execute()
           JOptionPane.showMessageDialog(null, "I'm about to execute!", "Testing", JOptionPane.PLAIN_MESSAGE);
            for(int i = 0; i < players.length; i++)
                try
                    players[i] = new Player(server.accept(), i);
                    runGame.execute(players);
    catch (IOException ie)
    stop();
    gameLock.lock();
    try
    players[Player1].setSuspended(false);
    otherPlayerConnected.signal();
    finally
    gameLock.unlock();
    Client.java
        public void init()
            startClient();
        public void startClient()
            try
                connection = new Socket(InetAddress.getByName(TienLenHost), 12345);
                input = new Scanner(connection.getInputStream());
                output = new Formatter(connection.getOutputStream());
            catch (IOException ie)
                stop();
            ExecutorService worker = Executors.newFixedThreadPool(1);
            worker.execute(this);
        }So after worker.execute(this), it should go to Server.java and run the function execute() right? But in my case, it doesn't. If you know how to fix this, please let me know. Thanks!

  • Client-Server side programing problem

    I designed a client-server program as seen below basis on serversocket and thread
    I use serversocket for making a host connection than people connect this socket via applet that i designed then they transffer data with socket.getInputStream() and socket.getOutputStream but it always happening between client and server how can i make theese streams transfer between clients is something like that possible if it is how?
    I couldnt send my hole java code because its too long and i wish i could explain my problem
        public void run()
            try
                servsocket = new ServerSocket(port);
                jTextArea1.append("Kullanici Girisi Bekleniyor.\n");
            catch(IOException e)
                jTextArea1.append("Sunucu Uzerinde Socket Acilamadi.\n");
                while(calisiyor)  //calisiyor variable is a boolean variable for checking if server is running
                    try
                    Socket sock = servsocket.accept();
                    background = new techsupportbackground(this,sock);
                    background.start();
                    catch(Exception e)
                        printstring("Hata:"+e);
                        break;
    this is the techsupportbackground classes run method it extends from thread
        public void run()
            if(!servicesetup()) return;
            support.printstring("Baglanti saglandi,kullanici basariyla giris yapti.");
            setPriority(MIN_PRIORITY);
            String sonmesaj = "";
            while(calisiyor)
                String mesaj = readinputline();
                if(mesaj == null) break;
                if (!sonmesaj.equals(mesaj))
                    support.printstring(username+"->"+mesaj);
                    sonmesaj = mesaj;
            cikis();
    and this is the client side program's run method
        public void run()
            try
                if(!doconnection())
                    client.printstring("Baglanti Saglanamadi:");
                    return;
            catch(Exception e)
                client.printstring("Baglanti Saglanamadi");
            while (calisiyor)
                String mesaj = readline();  //readline is the method which reads sockets input stream
                client.printstring(mesaj);
                    if (mesaj == null) break;
                    try {
                    Thread.sleep (client.timeupdate);
                    catch (InterruptedException e)
            if (server != null) closeserver();
            client.setdisconnected();
            client.printstring("Baglanti Koptu");

    I made two java file , one for server one for client
    server is working good openning the socket but the client is crashing when i attempt to connect to server
    here is my code if anyone could tell me where i made a mistake i would be very appreciate
    this is the client program
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.net.*;
    import javax.swing.*;
    import javax.swing.event.*;
    class client extends javax.swing.JFrame {
        private boolean baglandi;
        private MulticastSocket socket;
        private int port;
        private String ip;
        String username;
        private InetAddress group;
        private String msg;
        private DatagramPacket datawriter;
        private byte[] reader;
        private boolean calisiyor;
        private JScrollPane scrollpane;
        public client() {
            initComponents();
            this.setSize(490,450);
            jTextArea1.setEditable(false);
            jTextField2.setEditable(false);
            jButton2.setEnabled(false);
            jLabel3.setForeground(Color.RED);
            JPanel panel = new JPanel();
            panel.setLayout(new BorderLayout());
            panel.setBounds(0, 0, 480, 260);
            getContentPane().add(panel);
            scrollpane = new JScrollPane();
            scrollpane.getViewport().add(jTextArea1);
            panel.add(scrollpane,BorderLayout.CENTER);
            baglandi=false;
            ip="228.5.6.7";
            port=2222;
            try
            group = InetAddress.getByName(ip);
            msg ="";
            datawriter = new DatagramPacket(msg.getBytes(),msg.length(),group,port);
            calisiyor = false;
            catch(Exception e)
        private void initComponents() {
            jTextArea1 = new javax.swing.JTextArea();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jTextField1 = new javax.swing.JTextField();
            jTextField2 = new javax.swing.JTextField();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            jButton3 = new javax.swing.JButton();
            jLabel3 = new javax.swing.JLabel();
            getContentPane().setLayout(null);
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            getContentPane().add(jTextArea1);
            jTextArea1.setBounds(0, 0, 480, 260);
            jLabel1.setText("Kullanici Adi");
            getContentPane().add(jLabel1);
            jLabel1.setBounds(0, 270, 90, 15);
            jLabel2.setText("Mesaj");
            getContentPane().add(jLabel2);
            jLabel2.setBounds(0, 300, 60, 15);
            getContentPane().add(jTextField1);
            jTextField1.setBounds(100, 270, 290, 21);
            getContentPane().add(jTextField2);
            jTextField2.setBounds(100, 300, 290, 21);
            jButton1.setText("Gonder");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
            getContentPane().add(jButton1);
            jButton1.setBounds(400, 270, 80, 25);
            jButton2.setText("Gonder");
            jButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton2ActionPerformed(evt);
            getContentPane().add(jButton2);
            jButton2.setBounds(400, 300, 80, 25);
            jButton3.setText("Durdur");
            jButton3.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton3ActionPerformed(evt);
            getContentPane().add(jButton3);
            jButton3.setBounds(400, 340, 80, 25);
            jLabel3.setText("Baglanti Saglanamadi");
            getContentPane().add(jLabel3);
            jLabel3.setBounds(0, 360, 130, 15);
            pack();
        private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
            durdur();
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
            printoutput();
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            baslat();
        /** Exit the Application */
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
         * @param args the command line arguments
        public static void main(String args[]) {
            new client().show();
        public void baslat()
            username = jTextField1.getText();
            try
                socket = new MulticastSocket(port);
                socket.joinGroup(group);
            catch(IOException e)
                jTextArea1.append("Guvenlik Engellemesi Sebebiyle Sunucuya Ulasilamadi.\n");
                return;
                    jTextArea1.append("Sunucuya Baglanildi");
                    baglandi = true;
                    calisiyor = true;
                    jLabel3.setText("Baglanti Saglandi");
                    jTextArea1.append("Sunucuya Basariyla Baglanildi\n");
                    jLabel3.setForeground(Color.GREEN);
                    jButton1.setEnabled(false);
                    jTextField1.setEditable(false);
                    jButton2.setEnabled(true);
                    jTextField2.setEditable(true);
                while (calisiyor)
                        String mesaj = readline();
                        printstring(mesaj);
                        if (mesaj == null) break;
        public void durdur()
            jTextField2.setEditable(false);
            jTextField1.setEditable(true);
            jButton2.setEnabled(false);
            jButton1.setEnabled(true);
            jLabel3.setText("Baglanti Saglanamadi");
            jLabel3.setForeground(Color.RED);
            try
                socket.leaveGroup(group);
            catch(Exception e)
        public void printoutput()
            try
            String mesaj = jTextField2.getText();
            jTextField2.setText("");
            writeline(username+":->"+mesaj);
            catch(Exception e)
                printstring("Veri Ulastirilamadi.");
        public void printstring(String s)
            jTextArea1.append(s+"\n");
        public void setdisconnected()
            jTextField2.setEditable(false);
            jTextField1.setEditable(true);
            jButton2.setEnabled(false);
            jButton1.setEnabled(true);
            jLabel3.setText("Baglanti Saglanamadi");
            jLabel3.setForeground(Color.RED);
            public String readline()
                byte[] buf = new byte[1000];
                DatagramPacket datapack = new DatagramPacket(buf,buf.length);
                try
                    socket.receive(datapack);
                    String mesaj = buf.toString();
                    return mesaj;
                catch(Exception e)
                    printstring("Sunucuya Ulasilamadi");
                    return null;
        public void writeline(String s) throws IOException
                try
                    msg = s;
                    socket.send(datawriter);
                    printstring(msg);
                catch(Exception e)
                    printstring("Mesaj ulastirilamadi.");
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JButton jButton3;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JTextArea jTextArea1;
        private javax.swing.JTextField jTextField1;
        private javax.swing.JTextField jTextField2;
        // End of variables declaration
    this is the server program
    import java.net.*;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class techsupport extends javax.swing.JFrame implements ActionListener,Runnable {
        private MulticastSocket servsocket;
        private int port;
        private boolean calisiyor;
        private JScrollPane scrollpane;
        private techsupportbackground  background;
        private InetAddress group;
        public techsupport(String title) {
            super(title);
            initComponents();
            this.setSize(400,400);
            port=2222;
            jTextField1.addActionListener(this);
            jButton1.addActionListener(this);
            calisiyor=true;
            jTextArea1.setEditable(false);
            JPanel panel = new JPanel();
            panel.setLayout(new BorderLayout());
            panel.setBounds(0,10,400, 230);
            getContentPane().add(panel);
            scrollpane = new JScrollPane();
            scrollpane.getViewport().add(jTextArea1);
            panel.add(scrollpane,BorderLayout.CENTER);
                try
                group = InetAddress.getByName("228.5.6.7");
                catch(Exception e)
        private void initComponents() {
            jTextArea1 = new javax.swing.JTextArea();
            jButton1 = new javax.swing.JButton();
            jLabel1 = new javax.swing.JLabel();
            jButton2 = new javax.swing.JButton();
            jTextField1 = new javax.swing.JTextField();
            getContentPane().setLayout(null);
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            getContentPane().add(jTextArea1);
            jTextArea1.setBounds(0, 10, 400, 230);
            jButton1.setText("Start");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
            getContentPane().add(jButton1);
            jButton1.setBounds(160, 260, 80, 25);
            jLabel1.setText("Port");
            getContentPane().add(jLabel1);
            jLabel1.setBounds(0, 240, 120, 15);
            jButton2.setText("Stop");
            jButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton2ActionPerformed(evt);
            getContentPane().add(jButton2);
            jButton2.setBounds(250, 260, 90, 25);
            getContentPane().add(jTextField1);
            jTextField1.setBounds(0, 260, 130, 21);
            pack();
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
            try
            servsocket.close();
            jButton1.setEnabled(true);
            printstring("Port Kapatildi.");
            jTextArea1.setText("");
            catch(Exception e)
                printstring("Hata:"+e);
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
        public static void main(String args[]) {
            new techsupport("Teknik Destek Sunucu").show();
        public void actionPerformed(ActionEvent e) {
            boolean status = false;
            String komut = e.getActionCommand();
                if (komut.equals("Start"))
                    try
                        port = Integer.parseInt(jTextField1.getText());
                        jButton1.setEnabled(false);
                    catch(NumberFormatException err)
                        jTextArea1.append("Hatali Port Numarasi"+"\n");
                        jButton1.setEnabled(true);                   
                    Thread uygulama = new Thread(this);
                    uygulama.start();
                else if (komut.equals("Stop"))
                    calisiyor=false;
                    dispose();
        public void run()
            try
                servsocket = new MulticastSocket(port);
                servsocket.joinGroup(group);
                jTextArea1.append("Kullanici Girisi Bekleniyor.\n");
            catch(IOException e)
                jTextArea1.append("Sunucu Uzerinde Socket Acilamadi.\n"+e.toString());
        public void printstring(String s)
            jTextArea1.append(s+"\n");
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JTextArea jTextArea1;
        private javax.swing.JTextField jTextField1;
        // End of variables declaration
    }

  • Client Server program using Applets for client

    Creating a client server program using Applets for the clients.
    Having problems distrubting the message from client to client
    using ObjectOutputStreams/ObjectInputSteams.
    I can connect each client to simple server and respond with by writting
    the i/o stream of each client but unable to communicate from client to client. If any one out there has in tips of creating a class of objectOutputStreams that holds a array of ObjectOutputStreams and then broadcasts the message to every client, it would be much appreciated
    Thanks.

    Cheers poop for your reply
    I never explained the problem properly. What it is I am trying to set up a Client Server program using Applets as the clients GUI. The problem is broadcasting the message to multiply client connnection(s).
    Below is code, each client can connect and send message to the server. The problems is broadcasting the message to every client connection. The every client can input a message but only the last connected client can receive the message?????? Thanks in advance..
    /*this my server class */
    import java.io.*;
    import java.net.*;
    public class Server extends JFrame
    private static final int ServerPort=8080;
    private static final int MaxClients=10;
    private ObjectOutputStream output=null;
    private ObjectInputStream input=null;
    private BroadCastMessage broadcastMessage;
    public void runServer()          
    BroadCastMessage broadcastMessage= new BroadCastMessage();
    try
    {  //connect to server
    ServerSocket s = new ServerSocket(ServerPort,MaxClients);
         //listen to port 5000 for new connections
         ///max is 25
         System.out.println("Server listening on port "+ServerPort);
    while (state.isProgramRunning())
         try
         /// sGUI.waitForConnection();//new line
         s.setSoTimeout(100);
         //enable times in server-socket
         while (true)     
         Socket incoming = s.accept();
         //wait and accept connnections from serverSocket
         //instance of the class,pases the new connection and message
         //spawn as a thread
         SocketConnection connection=new SocketConnection(incoming,broadcastMessage);
         Thread a = new Thread(connection); a.start();
         System.out.println(state.getConnectionCount()+"Connection received from :"+incoming.getInetAddress());
         catch(InterruptedIOException x){}
    while (state.getConnectionCount()>0);
    System.exit(0);
    }catch (IOException e){}
    public static void main(String[] args)
    Server s =new Server();
         s.runServer();
    /*this is my socket connection thread*/
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    public class SocketConnection implements Runnable
    private ObjectOutputStream out;
    private ObjectOutputStream output=null;
    private ObjectInputStream input=null;
    private BroadCastMessage passOnMessage;
    private Socket theConnection=null;
    private String Inmessage="";
    private int Ocount;
    public SocketConnection(Socket caller,BroadCastMessage broadcastMessage,Ocount)
    theConnection =caller;///(5000,n)
    Ocount=ncount;
    passOnMessage=broadcastMessage;
    public void run()
    try
    getStreams();
    processConnection();
    catch(Exception e)
    {String clientDetails=("connection from IP Address: "+theConnection.getInetAddress());}
    private synchronized void getStreams() throws IOException
    { //get streams to send and receive data
    //set up output buffer to send header information
    ///Ocount++;
    //create new objectoutputstream
    output=passOnMessage.getOutputObject(output,theConnection,Ocount);
    ///flush output buffer to send header info.
    Ocount++;
    //set up input stream for objects
    input =new ObjectInputStream(
    theConnection.getInputStream());
    System.out.print("\nGot I/O streams\n");
    private synchronized void processConnection()throws IOException
    //process connection with client
    String Outmessage =" count : "+status.getConnectionCount();
    //send connection successful message to client
         Outmessage=Outmessage+"SERVER>>>Connection successful";
         output.writeObject(Outmessage);
    output.flush();
    do ///process messages sent from client
         try
         Inmessage = (String) input.readObject();
         System.out.println(Inmessage);
         /* //while the connection is open each line
         that is passed from the client to the server
         is read in and is displayed*/
         messageDetails.setMessage(Inmessage);
         String CurrentMessage=messageDetails.getMessage();
         //output.writeObject(CurrentMessage);
         // output.flush();
         passOnMessage.FloodMessage(CurrentMessage);
         //sending out the message
    catch(ClassNotFoundException classNotFoundException){}
    }while (!Outmessage.equals("CLIENT>>>TERMINATE"));
    /*this my attempt at broadcasting the message to all clients
    my thinking was that you could create a array of objectoutputstreams
    which in turn could be broadcasted(bit confussed here)*/
    import java.io.*;
    import java.net.*;
    public class BroadCastMessage /// implements Runnable
    private int count;
    private String Inmessage="";
    private ObjectOutputStream temp=null;
    private ObjectOutputStream[] output = new ObjectOutputStream [12];
    //temp level of array of objects
    public BroadCastMessage()
    count=0;
    public synchronized void FloodMessage(String message) throws IOException
    System.out.print(count);
         for(int i=0;i<count+1;i++)
         try
    {  System.out.print(count);
         output[count].writeObject(message);
         output[count].flush();
         catch(IOException ioException)
    {ioException.printStackTrace();}
         notifyAll();
    public ObjectOutputStream getOutputObject(ObjectOutputStream out,Socket caller,int Ocount)
    try
    { temp = new ObjectOutputStream(caller.getOutputStream());
         AddObjectOutputStream(temp,Ocount);
    ////FloodMessage();
         catch(IOException ioException)
    {ioException.printStackTrace();}
    return temp;     
    public void AddObjectOutputStream(ObjectOutputStream out,int Ocount)
    { ///add new object to array
    count=Ocount;
    output[count]=out;
    System.out.print("\nthe number of output streams : "+count+"\n");
    }

  • Connection Problem while client is behind proxy and server out side proxy

    hello
    i implemented ChatApplication in JAVA, for that i used socket connection when client and server both are in same network then it's working fine.
    but when my server is on internate and client is behind proxy and try to connect with server
    it not able to connect i get exception.
    i serch most of forum i got same answer and i try it but i was not success.
    any kind of help is appriciated.
    i attached my code(which i implement for testing ) pls reply me
    thanks in advance.
    Server.java
    import java.lang.*;
    import java.io.*;
    import java.net.*;
    class Server {
       public static void main(String args[]) {
          String data = "you are successfully connected with server.";
          try {
             ServerSocket srvs = new ServerSocket(1234);
             Socket skt = srvs.accept();
             System.out.print("Server has connected!\n");
             PrintWriter out = new PrintWriter(skt.getOutputStream(), true);
             System.out.print("Sending string: '" + data + "\n");
             out.print(data);
             out.close();
             skt.close();
             srvs.close();
          catch(Exception e) {
             System.out.print("Whoops! It didn't work!\n");
    ProxyClient.java
    import java.io.*;
    import java.net.*;
    import java.util.*;
    class ProxyClient{
       public static void main(String args[]) {
         String host="61.17.212.29";
         int port=1234;
               String line;
         Properties properties = System.getProperties();
         /*properties.put("firewallSet", "true");
         properties.put("firewallHost", "192.168.0.1");
         properties.put("firewallPort", "808");*/
         properties.put("socksProxySet","true");
         properties.put("socksProxyHost", "192.168.0.1");
         properties.put("socksProxyPort", "1080");
         System.setProperties (properties);
         try {
         /*SocketAddress addr = new InetSocketAddress("192.168.0.1", 1080);
         Proxy proxy = new Proxy(Proxy.Type.SOCKS, addr);
         Socket skt = new Socket(proxy);
         InetSocketAddress dest = new InetSocketAddress("61.17.212.29",1234);
         skt.connect(dest);*/
             System.out.println("before socket taken");
             Socket skt = new Socket(host,port);
             System.out.println("after socket taken");
             BufferedReader networkBin = new BufferedReader(new InputStreamReader(skt.getInputStream()));
             System.out.println("Received string: '");
             line = networkBin.readLine();     // Read one line
          while(true)
                 System.out.println(line);     // Output the line
                 line = networkBin.readLine(); // Read the next line, if any
          catch(Exception e) {
             System.out.print("Whoops! It didn't work!\n");
         e.printStackTrace();
    }

    Now look here. I could not care less about this
    code. I don't know anything about it, I don't
    want to know, I have already recommended you don't
    use it, and I have also given you a simpler and
    better solution. If you don't want to take my advice
    that is your privilege and your problem.ya i has understand system propertis i have setted and u can see it in the code i have tried by both system properties and also J2SE 5.0 proxy class but i got a same problem malformed Exception server refuse to connection.
    is there any problem at sever side?
    can u tell me in which way u r teling to set the propery i m looking forward for ur reply.
    ya i m sure u will give me.................reply "ejp".
    Thnx in advance.

  • FU Ant task failure: java.util.concurrent.ExecutionException: could not close client/server socket

    We sometimes see this failure intermitently when using the FlexUnit Ant task to run tests in a CI environment. The Ant task throws this exception:
    java.util.concurrent.ExecutionException: could not close client/server socket
    I have seen this for a while now, and still see it with the latest 4.1 RC versions.
    Here is the console output seen along with the above exception:
    FlexUnit player target: flash
    Validating task attributes ...
    Generating default values ...
    Using default working dir [C:\DJTE\commons.formatter_swc\d3flxcmn32\extracted\Source\Flex]
    Using the following settings for the test run:
    FLEX_HOME: [C:\dev\vert-d3flxcmn32\302100.41.0.20110323122739_d3flxcmn32]
    haltonfailure: [false]
    headless: [false]
    display: [99]
    localTrusted: [true]
    player: [flash]
    port: [1024]
    swf: [C:\DJTE\commons.formatter_swc\d3flxcmn32\extracted\build\commons.formatter.tests.unit.sw f]
    timeout: [1800000ms]
    toDir: [C:\DJTE\commons.formatter_swc\d3flxcmn32\reports\xml]
    Setting up server process ...
    Entry  [C:\DJTE\commons.formatter_swc\d3flxcmn32\extracted\build] already  available in local trust file at  [C:\Users\user\AppData\Roaming\Macromedia\Flash  Player\#Security\FlashPlayerTrust\flexUnit.cfg].
    Executing 'rundll32' with arguments:
    'url.dll,FileProtocolHandler'
    'C:\DJTE\commons.formatter_swc\d3flxcmn32\extracted\build\commons.formatter.tests.unit.swf '
    The ' characters around the executable and arguments are
    not part of the command.
    Starting server ...
    Opening server socket on port [1024].
    Waiting for client connection ...
    Client connected.
    Setting inbound buffer size to [262144] bytes.
    Receiving data ...
    Sending acknowledgement to player to start sending test data ...
    Stopping server ...
    End of test data reached, sending acknowledgement to player ...
    When the problem occurs, it is not always during the running of any particular test (that I am aware of). Recent runs where this failure was seen had the following number of tests executed (note: the total number that should be run is 45677): 18021, 18, 229.
    Here is a "good" run when the problem does not occur:
    Setting inbound buffer size to [262144] bytes.
    Receiving data ...
    Sending acknowledgement to player to start sending test data ...
    Stopping server ...
    End of test data reached, sending acknowledgement to player ...
    Closing client connection ...
    Closing server on port [1024] ...
    Analyzing reports ...
    Suite: com.formatters.help.TestGeographicSiteUrls
    Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.008 sec
    Suite: com.formatters.functionalUnitTest.testCases.TestNumericUDF
    Tests run: 13, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.071 sec
    Results :
    Tests run: 45,677, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 201.186 sec
    Has anyone else ran across this problem?
    Thanks,
    Trevor

    I am not sure if this information will help everyone, but here goes...
    For us, these problems with FlexUnit tests crashing the Flash Player appear to be related to couple of factors. Recently, we moved up from Flex 3.2 to Flex 4.1 as our development baseline.  Many people complained that their development environment (Flash Builder, etc.) was much more unstable.  Apparently, 4.1 produces SWFs that require more memory to run than 3.2 does?  Anyway, we still had Flash Player 10.1 as our runtime baseline.  Apparently, that version of the player was not as capable of running larger FlexUnit test SWFs, and would crash (as I posted months earlier).  I upgraded to the latest 10.3 standalone player versions, and the crashes have now ceased.  It would be nice to know exactly what was causing the crashes, but memory management (or lack of) is my best guess.
    So, if you are seeing these issues, try upgrading to the latest Flash Player version.
    Regards,
    Trevor

  • Socket communication between client and server

    Hi all,
    I am doing an assignment for communication between java client and java server using sockets. This communication is in the form of XML documents. I am facing a problem in this communication.
    Actually at Server side I'm creating an XML document(Document type object) using DocumentBuilderFactory in javax.xml.parsers package and transforming this Document into a stream using StreamResult.
    My code is :
    Transformer xmlTransformer = TransformerFactory.newInstance().newTransformer();
    StreamResult xmlString = new StreamResult(currentClientHandler.getSocketOutputStream());
    DOMSource xmlDocSource = new DOMSource(xmlDocument); // xmlDocument is Document type reference
    xmlTransformer.transform(xmlDocSource, xmlString);
    so, this xmlString(i.e. StreamResult) is passed directly into the output stream. Here I need to close() output stream after transform() call to help SAX parser to know about end of stream.
    Now at Client side, I am parsing this stream using SAX parser. It parses this correctly. But when sending some another data back to Server when client opens output stream, it given Socket closed exception. I know that closing input or output stream closes socket. But in my problem, I have to send data in streams and not by using files or byte[] etc.
    So what is nearest solution to problem ??
    Plz help me. Any kind of help will be greatly appreciated.

    hi
    thanks for ur reply.
    I didnt get any error msg while getting the back the datas.
    Actually i divided my application into two parts.
    My application will act as both server and client.
    server ll get the browser request and send to the client and the client will send that data to the c++ server.
    Im able to do that.and unable to get the data from server.
    Didnt get any error.
    can u tell me how to make an application to act as both client and server.
    I think im wrong in that part.
    thanks a lot

Maybe you are looking for

  • How do I post to a new page when the 1st page is full?

    How do you create a bul. board where the posts go on a 2nd page when the first page is filled ...and 3rd page when 2nd is full, etc ... Maybe I can stick a wordcount in a while loop before the CFOutPUT Tag? Is there such a variable that holds a word

  • Splitting datamatrix by output frequency

    Hi, I have trouble finding out how to solve a problem in Labview I am working on improving a program so that it may present data in different frequencies. My NI6211 reads 1000 analog samples per channel and second. I want to be able to display this d

  • Service working n IE 7 but not working in IE 6

    Hi Experts, We are using SRM 4.0. We have developed a Z transaction with 2 screens. We have created the internet service and templates also. When I run this transaction in IE 6 the first screen id displayed correctly, but when I click any buttons tha

  • How to add the mail.jar file to my CLASSPATH ?

    Hi; I wish to Instal JavaMail 1.2 To use the JavaMail 1.2 API, i unbundle the javamail-1_3_1-upd.zip file.....and now, i would like to add the mail.jar file to your CLASSPATH. My question is: how do you do this ? - ok i did that for CATALINA_HOME & J

  • IPod Playlist in Reverse Order

    I've seen quite a few people around the web having this issue. On my 3G iPod I would simply resync with iTunes, and it would correct this issue. I have a "Recently Added" playlist in iTunes, and now when I scroll to that Playlist on my iPod Classic,