Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Sockets in JApplet

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Sockets in JApplet

    I have tried to make an JApplet of our Chess Application..!
    And I m stuck at making an socket connection for it..!
    The Problem is that when I run the applet applet using NetBeans Socket connection works fine and it sends the message to server..!!
    But when I open it in the browser.. Applet Doesn't seems to send any message to the server..!!

    If Any Body Can put an example code for it..!!
    Help!

    Applet is at Applet HTML Page

    Thnx!!


  2. #2
    Junior Member
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sockets in JApplet

    Here is the Connection Object


    package com.shrey.mychessapplet;

    import java.io.*;
    import java.net.*;

    public class Connection {

    Socket soc;
    PrintWriter pw;

    public Connection() {

    try {
    InetAddress str1 = InetAddress.getByName("shrey.dyndns.org");
    // System.out.println(str1);
    soc = new Socket(str1, 8091);
    pw = new PrintWriter(new BufferedWriter(
    new OutputStreamWriter(soc.getOutputStream())), true);
    pw.println("hiiiii"); //Message to Server
    } catch (Exception ex) {
    }

    }
    public PrintWriter getPw() {
    return pw;
    }
    }

  3. #3

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,198
    Thanks
    49
    Thanked 2,173 Times in 2,146 Posts

    Default Re: Sockets in JApplet

    Are there any error messages in the browser's java console window?

    Are you loading the html and applet from the server that the applet is trying to connect to?

  5. #5
    Member
    Join Date
    Jun 2011
    Posts
    56
    Thanks
    2
    Thanked 7 Times in 6 Posts

    Default Re: Sockets in JApplet

    Quote Originally Posted by shrey.haria View Post
    I have tried to make an JApplet of our Chess Application..!
    And I m stuck at making an socket connection for it..!
    The Problem is that when I run the applet applet using NetBeans Socket connection works fine and it sends the message to server..!!
    But when I open it in the browser.. Applet Doesn't seems to send any message to the server..!!

    If Any Body Can put an example code for it..!!
    Help!

    Applet is at Applet HTML Page

    Thnx!!
    To OP:
    The applet have to be signed. I happen to have a java applet for my chess engines (computer programs that
    play chess). I am working a game server/client using java (mainly to study the language it self). I use sockets
    to make a TCP connection to well known game servers like FICS,ICC etc.. Applets have many restrictions unless signed:
    socket connections, open/save files and many other things. You can find the applet here towards the end
    of the page https://sites.google.com/site/dshawul/ . It might take sometime to load and will ask your permissions
    to open socket connections and other restricted stuff.

    Question for myself:
    How do I get a website up on which I want to make live broadcasts. What I want is NOT the Multicast class in java
    but simply a dynamic webpage with a board that gets updated every move. Users do not have to make connections.

    Thank you

Similar Threads

  1. JApplet Not Running In Firefox
    By aussiemcgr in forum Java Theory & Questions
    Replies: 13
    Last Post: August 13th, 2011, 08:40 AM
  2. initializing a java JApplet
    By j_a_lyons in forum Java Theory & Questions
    Replies: 0
    Last Post: January 8th, 2011, 03:49 PM
  3. japplet - jtable - browser
    By jasonnuigi in forum AWT / Java Swing
    Replies: 4
    Last Post: January 2nd, 2011, 04:20 AM
  4. Convert Application to JApplet
    By MikeSki3 in forum AWT / Java Swing
    Replies: 2
    Last Post: May 12th, 2010, 01:20 PM
  5. Cannot update Jlabel in JApplet
    By rin in forum Java Applets
    Replies: 2
    Last Post: April 17th, 2010, 08:21 AM