Simple server/client socket in applets code.

Can anyone please help me with Java sockets ? I want to create an applet that simply checks if it's still online. This means that i'll be using this applet thru modem(that is, dial-up connection). All i want the applet to do is send a signal to the server and the server answer back that it is still online. The server should be able to handle multiple sends and receives. I need just a simple code for me to work on (both server and client). The client doesn't have to send any special message to the server and vice versa.
Thanks.

Below is the code for both Applet and Servlet .I think this will solve your problem.
Applet:
import java.applet.*;
import java.awt.*;
import java.io.*;
import java.net.*;
public class OnlineApplet extends Applet implements Runnable
     private static Thread thread;
     private static HttpURLConnection URLConn;
     public void init()
          try
               //Connect to the URL where servlet is running.
               URL url = new URL("http://localhost/servlet/OnlineServlet");
               URLConn = (HttpURLConnection)url.openConnection();
               URLConn.setDoInput(false);
               URLConn.setDoOutput(true);
          catch (Exception ex)
          thread = new Thread(this);
     public void start()
          thread.start();
     public void paint(Graphics g) {}
     public void stop() { }
     public void destroy() { }
     public void run()
          while(true)
               try
                    thread.sleep(1000 * 60);
                    sendConfirmation();
               catch (Exception ex)
     private void sendConfirmation() throws Exception
          DataOutputStream dos = new DataOutputStream(URLConn.getOutputStream());
          dos.writeChars("Fine");
          dos.flush();
          dos.close();
Servlet:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class OnlineServlet extends HttpServlet implements Runnable
     public static Hashtable hsh;
     private static Thread thread;
     public void init(ServletConfig scon) throws ServletException
          hsh = new Hashtable();
          thread = new Thread(this);
     public void service(HttpServletRequest req, HttpServletResponse res)
          String strHostName = req.getRemoteHost();
          if(hsh.containsKey(strHostName))
               updateHash(strHostName);
          else
               hsh.put(strHostName, System.currentTimeMillis() + "");
     private void updateHash(String strHostName)
          hsh.remove(strHostName);
          hsh.put(strHostName, System.currentTimeMillis() + "");
     public void run()
          while(true)
               try
                    thread.sleep(1000 * 120);
               catch (Exception ex)
               validateUsers(System.currentTimeMillis());
     private void validateUsers(long msec)
          Enumeration keys = hsh.keys();
          int size = hsh.size();
          while(keys.hasMoreElements())
               String strKey = keys.nextElement().toString();
               String strLong = hsh.get(strKey).toString();
               long lg1 = Long.parseLong(strLong);
               if((lg1 - msec) > 100000)
                    // This means there is no response from user . That means he is not online. So you can remove from hashtable.
                    hsh.remove(strKey);

Similar Messages

  • Server/Client Socket Connection

    Hi, I am trying to program a simple server/client socket connection program, the main function is to send and receive objects between them. I somehow went wrong and the connection between them keeps terminating right after establishing connection. Is there anything I can do to resolve this?
    This is gonnna be kinda long post.. sorry. These are the code that starts and ends the socket connection. I'm kinda desperate for this to work.. so thanks in advance.
    appinterface.java:
    //Set up server to receive communications; process connections. 1x.
         public void runServer () {
              try {
                   //Create a ServerSocket
                   server = new ServerSocket(12345, 100);
                   try {
                             waitForSockConnection();     //Wait for a connection.
                             getSockStreams();               //Get input & output streams.
                             establishDbConnection();     //Open up connection to DB.
                   finally {
                             closeSockConnection(); //Close connection.
              //Process problems with I/O
              catch(IOException ioException) {
                   displayMessage("I/O Error: " + ioException);
                   runServer();
         //Wait for connection to arrive, then display connection info
         private void waitForSockConnection() throws IOException {
              displayMessage("Waiting for connection");
              connection = server.accept(); //Allow server to accept connection.
              displayMessage("Connection received from: " + connection.getInetAddress().getHostName());
         //Get streams to send and receive data.
         private void getSockStreams() throws IOException {
              //Set up output streams for objects
              ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream());
              output.flush(); //Flush output buffer to send header information.
              //Set up input stream for objects.
              ObjectInputStream input = new ObjectInputStream(connection.getInputStream());
              try {
              classHolderServer holderObj = new classHolderServer();
              holderObj = (classHolderServer)input.readObject();
              processSockConnection(holderObj);
              displayMessage("Got I/O Streams");
              //Catch problems reading from client
              catch (ClassNotFoundException classNotFoundException) {
                             displayMessage("Unknown object type received");
         //Process connection with client.
         private void processSockConnection(classHolderServer holderObj) throws IOException {
              //sendMessage("Connection Successful");
                        //True is query, and false is auth.
                        if(holderObj.type1==true)
                             processDbStatement(holderObj.type2, holderObj.sqlquery);
                        else {
                             authCheck(holderObj.userName, holderObj.passWord);
                             if(!authCheck)
                             closeDbConnection();
         //Send messages to client.
         private void sendMessage(String message) {
              // Send message to client
              try {
                   ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream());
                   output.flush();
                   output.writeObject(message);
                   output.flush();
                   displayMessage("Message Sent:" + message);
              catch (IOException ioException) {
                   displayMessage("\nError Sending Message: " + message);
         //Send object to client
         private void sendObject(Object holderObj) {
                   // Send object to client
                   try {
                        ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream());
                        output.writeObject(holderObj);
                        output.flush();
                        displayMessage("\nObject sent");
                   //Process problems sending object
                   catch (IOException ioException) {
                        displayMessage("\nError writing object");
         //Close streams and socket.
         private void closeSockConnection() {
                   displayMessage("Terminating connection");
                   try {
                        //output.close();
                        //input.close();
                        connection.close();
                        closeDbConnection();
                        this.userName = null;
                        this.passWord = null;
                        this.receiverId = 0;
                        this.authCheck = false;
                   catch (IOException ioException) {
                        displayMessage("I/O Error: " + ioException);
              }Client:
    private void runClient() {
              //Connect to sever and process messages from server.
              try{
                   connectToServer();
                   getStreams();
                   processConnection();
              //Server closed connection.
              catch(EOFException eofException) {
                   //displayMessage"Client Terminated Connection");
              //Process problems communicating with server.
              catch (IOException ioException) {
                   //displayMessage"Communication Problem");
              finally {
                   closeConnection();
         //Connect to server
         private void connectToServer() throws IOException {
              //displayMessage("Attempting connection\n");
              //Create Socket to make connection to sever.
              client = new Socket(InetAddress.getByName(chatServer), 12345);
              //Display connection information
              //displayMessage("Connected to: " + client.getInetAddress().getHostName());
         //Get streams to send and receive data.
         private void getStreams() throws IOException {
              //Set up output stream for objects.
              ObjectOutputStream output = new ObjectOutputStream(client.getOutputStream());
              output.flush(); //Flush outout buffer to send header information.
              //Set up input stream for objects.
              ObjectInputStream input = new ObjectInputStream(client.getInputStream());
              //displayMessage("\nGot I/O streams\n");
         //Close socket connection.
         private void closeConnection() {
              //displayMessage("\nClosing connection");
              try {
                   ObjectOutputStream output = new ObjectOutputStream(client.getOutputStream());
                   output.close();
                   ObjectInputStream input = new ObjectInputStream(client.getInputStream());
                   input.close();
                   client.close();
                   authCheck=false;
              catch(IOException ioException) {
                   ioException.printStackTrace();
         //Send data to server.
         private void sendObject(classHolderClient queryObj) {
              try {
                   output.writeObject(queryObj);
                   output.flush();
                   //displayMessage("Please wait..");
              //Process problems sending object.
              catch (IOException ioException) {
                   //displayMessage("\nError writing object");
         //Process connection with server.
         private void processConnection() throws IOException {
              try{
                   classHolderClient holderObj = new classHolderClient();
                   holderObj = (classHolderClient)input.readObject();
                   if(holderObj.type2==2) {
                             this.authCheck=holderObj.authCheck;
                             this.userName=holderObj.userName;
                             this.passWord=holderObj.passWord;
              catch(ClassNotFoundException classNotFoundException) {
                   //displayMessage(classNotFoundException);
              }

    private ObjectOutputStream output = new ObjectOutputStream(client.getOutputStream());Like this? But this will cause an error asking me to catch an exception:
    C:\Documents and Settings\Moon\My Documents\Navi Projects\School\OOPJ Project\Prototype\GPS-Lite v2 Alpha Debugger\client.java:41: unreported exception java.io.IOException; must be caught or declared to be thrown
            private ObjectOutputStream output = new ObjectOutputStream(client.getOutputStream());
                                                                                             ^
    C:\Documents and Settings\Moon\My Documents\Navi Projects\School\OOPJ Project\Prototype\GPS-Lite v2 Alpha Debugger\client.java:41: unreported exception java.io.IOException; must be caught or declared to be thrown
            private ObjectOutputStream output = new ObjectOutputStream(client.getOutputStream());
                                                ^
    2 errors

  • Simple Server/Client Applet example code ???

    Hi to all.
    I would like to ask if possible to someone to tell me some example code to do this simple thing:
    I want an applet showing only a TextField and a button. When the user writes something on the textfield and press the button, it should send the text in the textfield to the "server", and then it should save it in a variable.
    I think there should be 2 different classes at least (server and client), but no idea in how could I make this on Java.
    So I am asking if possible for some sample code for make this.
    Thank you for the information
    John

    hello!
    Here is a console based Server which will recieve the string and disply on the DOS screen.
    /////////////////////////////////// Server /////////////////
    import java.net.*;
    import java.io.*;
    import java.util.*;
    public class ChatServer extends Thread
    ServerSocket ssSocket;
    Socket sSocket;
    public BufferedReader in;
    public PrintWriter out;
    public ChatServer()
         try
         ssSocket = new ServerSocket (4000);
         catch(IOException e)
         System.out.println (e);
    public void run()
    try
         sSocket = ssSocket.accept();
         if(sSocket != null)
              in = new BufferedReader(new InputStreamReader(sSocket.getInputStream()));
              out = new PrintWriter(sSocket.getOutputStream(), true);
    String str = in.readLine();
         System.out.println (str);
         catch(IOException e)
              System.out.println (e);
    public static void main (String []args)
              Thread th = (Thread) new ChatServer();
              th.start();     
    ///////////////////////// Client //////////////////////
    public class Client extends Applet implements ActionListener
    public Socket sClient;
    public BufferedReader in;
    public PrintWriter out ;
    String str;
    private TextField txt = new TextField();
    private Button btn = new Button ("OK");
    public void init()
         try
         sClient = new Socket ("localhost" , 4000);
         in = new BufferedReader(new InputStreamReader(sClient.getInputStream()));
         out = new PrintWriter(sClient.getOutputStream(), true);
         catch (UnknownHostException uhe)
         catch (IOException ioe)
         System.out.println (" I/O Exception : " + ioe);
         setLayout(new FlowLayout());
         txt.setColumns (20);
         add(txt);
         add(btn);
         btn.addActionListener(this);
    public void actionPerformed(ActionEvent AE)
         if(AE.getSource() == btn)
         str = txt.getText();
         out.println(str);
    now u should try it and improve it according to ur need...
    Ahmad Jamal.

  • Java Chat (Server, Client Socket Connection)

    Assignment:
    The assignment is to deliver two source codes that can run a Server (1) and Clients (2) in order to create a simpel chat program. The server has to wait and check an IP (localhost) + Port, and the client has to connect to that port and create a socket connection. The only thing that should be done is create a new socket connection for each client... and when a client sends a message, the message should be delivered to all clients connected to the server.
    Problem...
    However I can read an edit Java, it's difficult for me to write it. I allready found many turturials about socket connections on the internet, and tried to edit those, but they don't really do what I want unless I really write new shit. Is there a way you guys can help me with this, or that you find a really good website that fits my question?

    According to me ,
    take string variable 'str'
    Take some class ,I think u already taken.....
    Scoket scoket = new Socket(IP,port);
    OutputStream out;
    IInputStream in;
    in = socket.getInputStream();
    out = socket.getOutputStream();
    If sends the msg then use
    out.writeObject(str);
    This line sends data to the other user
    msg resivce from client then use
    str = in.readInput();
    & this str set to the any objects out put .
    Such as TextField.setText(str);
    //Server.class
    import java.io.EOFException;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.net.ServerSocket;
    import java.net.Socket;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    public class Server extends JFrame
              private JTextField enterdField;
              private JTextArea displayArea;
              private ObjectOutputStream output;
              private ObjectInputStream input;
              private ServerSocket server;
              private Socket connection;
              private int counter=1;
              public Server()
                        super("Server");
                        enterdField = new JTextField();
                        enterdField.setEditable(false);
                        enterdField.addActionListener(
                             new ActionListener()
                                       public void actionPerformed(ActionEvent event)
                                                 sendData(event.getActionCommand());
                                                 //System.out.println(event.getActionCommand());
                                                 enterdField.setText("");
                   add(enterdField,BorderLayout.NORTH);
                   displayArea = new JTextArea();
                   add(new JScrollPane(displayArea),BorderLayout.CENTER);
                   setSize(300,150);
                   setVisible(true);
              public void runServer()
                        try
                                  server = new ServerSocket(12345,100);
                                  while(true)
                                            try
                                                      waitForConnection();
                                                      getStreams();
                                                      processConnection();
                                            catch(EOFException eofexception)
                                                      displayMessage("\nServer terminated connection");
                                            finally
                                                      closeConnection();
                                                      counter++;
                        catch(IOException ioException)
                                  ioException.printStackTrace();
              private void waitForConnection() throws IOException
                        displayMessage("Waiting for connection");
                        connection = server.accept();
                        //System.out.println(server.accept());
                        System.out.println(connection.getInetAddress());//Server Address and Hostname.
                        displayMessage("Connection"+counter +"received from :"+connection.getInetAddress().getHostName());
              private void getStreams() throws IOException
                        System.out.println("Start getStream");
                        output = new ObjectOutputStream(connection.getOutputStream());
                        output.flush();
                        input = new ObjectInputStream(connection.getInputStream());
                        displayMessage("\nGot I/O stream\n");
              private void processConnection() throws IOException //Read data from Client for Server.
                        String message="Connection sucessful To Client";
                        sendData(message);
                        int i=0;
                        setTextFieldEditable(true);
                        do
                                  try
                                            message =(String) input.readObject();//For Client
                                            System.out.println("Input from :"+message);//From Client
                                            displayMessage("\n" + message);
                                            System.out.println("\n" + i++);
                                  catch(ClassNotFoundException classnotfoundexception)
                                            displayMessage("\nUnknown object type recived");
                        while(!message.equals("CLIENT>>>TERMINATE"));
              private void closeConnection()
                        displayMessage("\nTeminating connection");
                        setTextFieldEditable(false);
                        try
                                  output.close();
                                  input.close();
                                  connection.close();
                        catch(IOException ioException)
                                  ioException.printStackTrace();
              private void sendData(String message)//Write data to the Client from the Server.
                        try
                                  output.writeObject("SERVER>>>"+message);//For Client side.
                                  System.out.println(message);
                                  output.flush();
                                  displayMessage("\nSERVER>>>"+message);//On server side.
                        catch(IOException ioException)
                                  displayMessage("\nError writing object");
              private void displayMessage(final String messageToDisplay)
                        SwingUtilities.invokeLater(
                             new Runnable()
                                  public void run()
                                            displayArea.append(messageToDisplay);
              private void setTextFieldEditable(final boolean editable)
                        SwingUtilities.invokeLater(
                             new Runnable()
                                  public void run()
                                            enterdField.setEditable(editable);
              public static void main(String q[])
                        Server app = new Server();
                        app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        app.runServer();
    //Client.class
    import java.io.EOFException;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.net.InetAddress;
    import java.net.Socket;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    public class Client extends JFrame
         private JTextField enterField;
         private JTextArea displayArea;
         private ObjectOutputStream output;
         private ObjectInputStream input;
         private String message="";
         private String chatServer;
         private Socket client;
         public Client (String host)
                   super("Client");
                   chatServer=host;
                   enterField = new JTextField();
                   enterField.setEditable(false);
                   enterField.addActionListener(
                        new ActionListener()
                                  public void actionPerformed(ActionEvent event)
                                            sendData(event.getActionCommand());
                                            enterField.setText("");
                        add(enterField,BorderLayout.NORTH);
                        displayArea = new JTextArea();
                        add(new JScrollPane(displayArea),BorderLayout.CENTER);
                        setSize(300,150);
                        setVisible(true);
         public void runclient()
                   try
                             connectToServer();
                             getStreams();
                             processConnection();
                   catch(EOFException eofException)
                             displayMessage("\nClient treminated connection");
                   catch(IOException ioException)
                             ioException.printStackTrace();
                   finally
                             closeConnection();
         private void connectToServer() throws IOException
                   displayMessage("Attempting connection\n");
                   client = new Socket(InetAddress.getByName(chatServer),12345);
                   displayMessage("Connect to:"+client.getInetAddress().getHostName());
         private void getStreams() throws IOException
                   output = new ObjectOutputStream(client.getOutputStream());
                   output.flush();
                   input = new ObjectInputStream(client.getInputStream());
                   //Thread t = new Thread(this,"Thread");
                   //t.start();
                   displayMessage("\nGot I/O stream\n");
         private void processConnection( ) throws IOException
                   setTextFieldEditable(true);
                   do
                             try
                                       message=(String)input.readObject();
                                       displayMessage("\n"+message);
                             catch(ClassNotFoundException classnotfoundexception)
                                       displayMessage("\nUnknown object type received");
                   while(!message.equals("SERVER>>>TERMINATE"));
         private void closeConnection()
                   displayMessage("\n Closing connection");
                   setTextFieldEditable(false);
                   try
                             output.close();
                             input.close();
                             client.close();
                   catch(IOException ioException)
                             ioException.printStackTrace();
         private void sendData(String message)
                   try
                             output.writeObject("CLIENT>>>"+message);
                             //System.out.println(message);
                             output.flush();
                             displayMessage("\nCLIENT>>>"+message);
                   catch(IOException ioException)
                             displayArea.append("\n Error writing object");
         private void displayMessage(final String MessageToDisplay)
                   SwingUtilities.invokeLater(
                        new Runnable()
                                  public void run()
                                            displayArea.append(MessageToDisplay);
         private void setTextFieldEditable(final boolean editable)
                   SwingUtilities.invokeLater(
                        new Runnable()
                                  public void run()
                                            enterField.setEditable(editable);
         public static void main(String q[])
                   Client app;
                   if(q.length==0)
                             app = new Client("127.0.0.1");
                   else
                             app = new Client(q[0]);
                   app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   app.runclient();
    Use this example .....
    Give me reply.My method is correct or not
    All the best

  • My first Server/Client Program .... in advise/help

    Hello,
    I am learning about Sockets and ServerSockets and how I can use the. I am trying to make the simplest server/client program possible just for my understanding before I go deper into it. I have written two programs. theserver.java and theclient.java the sere code looks like this....
    import java.net.*;
    import java.io.*;
    import java.util.*;
    public class theserver
      public static void main(String[] args)
      {   //  IOReader r = new IOReader();
            int prt = 3333;
            BufferedReader in;
             PrintWriter out;
            ServerSocket serverSocket;
            Socket clientSocket = null;
    try{
    serverSocket = new ServerSocket(prt);  // creates the socket looking on prt (3333)
    System.out.println("The Server is now running...");
    while(true)
        clientSocket = serverSocket.accept(); // accepts the connenction
        clientSocket.getKeepAlive(); // keeps the connection alive
        out = new PrintWriter(clientSocket.getOutputStream(),true);
        in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
         if(in.ready())
         System.out.println(in.readLine()); // print it
    catch (IOException e) {
        System.out.println("Accept failed:"+prt);
    and the client looks like this
    import java.net.*;
    import java.io.*;
    public class theclient
    public static void main(String[] args)
        BufferedReader in;
        PrintWriter out;
        IOReader r = new IOReader();
        PrintWriter sender;
        Socket sock;
      try{
        sock = new Socket("linuxcomp",3333);  // creates a new connection with the server.
        sock.setKeepAlive(true); // keeps the connection alive
        System.out.println("Socket is connected"); // confirms socket is connected.
        System.out.println("Please enter a String");
         String bob = r.readS();
          out = new PrintWriter(sock.getOutputStream(),true);
        out.print(bob); // write bob to the server
      catch(IOException e)
           System.out.println("The socket is now disconnected..");
    If you notice in the code I use a class I made called IOReader. All that class is, is a buffered reader for my System.in. (just makes it easier for me)
    Ok now for my question:
    When I run this program I run the server first then the client. I type "hello" into my system.in but on my server side, it prints "null" I can't figure out what I am doing wrong, if I am not converting correctly, or if the message is not ever being sent. I tried putting a while(in.read()) { System.out.println("whatever") } it never reaches a point where in.ready() == true. Kinda of agrivating. Because I am very new to sockets, I wanna aks if there is somthing wrong with my code, or if I am going about this process completely wrong. Thank you to how ever helps me,
    Cobbweb

    here's my simple server/client Socket :
    Server:
    import java.net.*;
    import java.io.*;
    public class server
       public static void main(String a[])
              ServerSocket server=null;
              Socket socket=null;
              DataInputStream input=null;
              PrintStream output=null;
          try
             server=new ServerSocket(2000);
             socket=server.accept();
             input = new DataInputStream(socket.getInputStream());
             output = new PrintStream(socket.getOutputStream());
             //output.println("From Server: hello there!");
             String msg="";
             while((msg=input.readLine()) != null)
                System.out.println("From Client: "+msg);
          catch(IOException e)
          catch(Exception e)
    }Client:
    import java.net.*;
    import java.io.*;
    public class client
       static private Socket socket;
       static private DataInputStream input;
       static private PrintStream output;
       public static void main(String a[])
          try
    socket=new Socket("10.243.21.101",2000);
    System.out.println("\nconnected to: \""+socket.getInetAddress()+"\"");
             input=new DataInputStream(socket.getInputStream());
             output=new PrintStream(socket.getOutputStream());
             output.println("From Client(Tux): "+a[0]);
             String msg="";
             //while((msg=input.readLine()) != null)
                 System.out.println("From Server(Bill): "+msg);
          catch(java.io.IOException e)
          catch(Exception e)
    }

  • Server/Client connection using an actionListener

    Hey guys,
    New to this board, so hopefully I can be of assistance :)
    What I am currently working on is a networked Monopoly game. My part of the assignment is to create a simple game lobby (just GUI based, buttons, action listeners, etc) where players can create games and join games already created.
    What I have is this. When a player clicks on the "Create Game" button, an anonomus inner action listener will detect the push and create a hosted game (Server side connection). When a player clicks on the newly created game, they will be a joined player (Client side connection).
    The problem is this, keep in mind that I have created a very, very simple server/client chat to test this out. When a Socket is created for the clients to connect to upon the Create Game button push, my program essentially just hangs. Nothing happens at all.
    Here are the 3 classes I used. I understand this is probably not the most efficient way to post, but this is the only way you can see what I exactly have. I took out all my GUI stuff to make it easier to follow (if you want me to post full classes I can):
    Thanks for all the help!
    - Ry
    //package Mackopoly;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.BorderLayout;
    import java.io.EOFException;
    import java.io.IOException;
    import java.net.ServerSocket;
    import java.io.EOFException;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.net.ServerSocket;
    import java.net.Socket;
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    import javax.swing.JFrame;
    public class gameList extends JFrame {
        MackPlayer tc1;
        MackPlayer tc2;
        MackPlayer tc3;
        HostPlayer ts1;
        HostPlayer ts2;
        HostPlayer ts3;
        private String temp = ""; //used to display chat area
        private int gameCounter = 0; //number of games created
        private boolean game1Started = false;
        private boolean game2Started = false;
        private boolean game3Started = false;
        public void start()
        //Sets up the screen
            enterField.addActionListener(
            new ActionListener()
                public void actionPerformed(ActionEvent ae)
                    if (ae.getSource() == enterField)
                        temp = enterField.getText();
                        chatBox.append(temp + "\n");
                        enterField.setText("");
            createGame.addActionListener(
            new ActionListener()
                public void actionPerformed(ActionEvent ae)
                    if (ae.getSource() == createGame)
                        gameCounter++;
                        if(gameCounter == 1)
                            //create a new host game on the server
                            //instanciate an object accordingly
                            game1.setText("Game " + gameCounter + "started!");
                            game1Started = true;
                                  ts1 = new HostPlayer();
                            ts1.execute();
                        else if(gameCounter == 2)
                            game2.setText("Game " + gameCounter + "started!");
                            game2Started = true;
                                  ts2 = new HostPlayer();
                            ts2.execute();
                        else if(gameCounter == 3)
                            game3.setText("Game " + gameCounter + "started!");
                            game3Started = true;
                                  ts3 = new HostPlayer();
                             ts3.execute();
                        else
                            System.out.println("games full");
            joinGame1.addActionListener(
            new ActionListener()
                public void actionPerformed(ActionEvent ae)
                    if (ae.getSource() == joinGame1)
                        if(game1Started == false)
                            JOptionPane.showMessageDialog(null,"Start a game!");
                        if(game1Started == true)
                            JOptionPane.showMessageDialog(null,"Joined!");
                            tc1 = new MackPlayer("Game 1");
                            tc1.startClient();
            joinGame2.addActionListener(
            new ActionListener()
                public void actionPerformed(ActionEvent ae)
                    if (ae.getSource() == joinGame2)
                        if(game2Started == false)
                            JOptionPane.showMessageDialog(null,"Start a game!");
                        if(game2Started == true)
                             JOptionPane.showMessageDialog(null,"Joined!");
                            tc2 = new MackPlayer("Game 2");
                            tc2.startClient();
            joinGame3.addActionListener(
            new ActionListener()
                public void actionPerformed(ActionEvent ae)
                    if (ae.getSource() == joinGame3)
                        if(game3Started == false)
                            JOptionPane.showMessageDialog(null,"Start a game!");
                        if(game3Started == true)
                             JOptionPane.showMessageDialog(null,"Joined!");
                            tc3 = new MackPlayer("Game 3");
                            tc3.startClient();
        }//End start method
    }//End of my class
    import java.awt.*;
    import java.awt.event.*;
    import java.net.Socket;
    import java.net.InetAddress;
    import java.io.IOException;
    import javax.swing.*;
    import java.util.Formatter;
    import java.util.Scanner;
    import java.util.concurrent.Executors;
    import java.util.concurrent.ExecutorService;
    //Imports necessary packages
    public class MackPlayer extends JFrame implements Runnable
    //Client class
         private JTextField idField;
         private JTextArea displayArea;
         private JTextField guessArea;
         private JPanel panel2;
         private Socket connection;
         private Scanner input;
         private Formatter output;
         private String Host;
         private String myMark;
         private boolean myTurn;
         private final String X_MARK = "1";
         private final String O_MARK = "2";
         public MackPlayer(String host)
              Host = host;
              displayArea = new JTextArea(10,30);
              displayArea.setEditable(false);
              add(new JScrollPane(displayArea), BorderLayout.SOUTH);
              //Creates the message area
              idField = new JTextField();
              idField.setEditable(false);
              add(idField, BorderLayout.NORTH);
              //Creates the name field
              guessArea = new JTextField(10);
              guessArea.setEditable(false);
              add(new JScrollPane(guessArea), BorderLayout.CENTER);
              //Creates the guess area
              panel2 = new JPanel();
              panel2.add(guessArea, BorderLayout.CENTER);
              add(panel2, BorderLayout.CENTER);
              setSize(350, 275);
              setVisible(true);
              TextHandler tHandler = new TextHandler();
              idField.addActionListener(tHandler);
              guessArea.addActionListener(tHandler);
              //Adds the area's to the handler
              startClient();
         public void startClient()
         //Gets connection and starts thread
              try
                   connection = new Socket(InetAddress.getByName(Host), 12345);
                   input = new Scanner(connection.getInputStream());
                   output = new Formatter(connection.getOutputStream());
              catch(IOException e)
                   e.printStackTrace();
              ExecutorService worker = Executors.newFixedThreadPool(1);
              worker.execute(this);
         public void run()
              myMark = input.nextLine();
              SwingUtilities.invokeLater(
              new Runnable()
                   public void run()
                        idField.setText("Enter name here");
                        guessArea.setText("Enter guess");
                        //Default text
              );//end call
              myTurn = (myMark.equals(X_MARK));
              while(true)
                   if(input.hasNextLine())
                        processMessage(input.nextLine());
         private void processMessage(String message)
         //Handles all possible messages from the server
              if(message.equals("Guess too low."))
                   displayMessage("Guess too low\n");
              else if(message.equals("Guess too high."))
                   displayMessage("Guess too high\n");
              else if(message.equals("You Win!"))
                   displayMessage("You Win!\n");
              else if(message.equals("Other player connected.  Your turn."))
                   displayMessage("Other player connected.  Your turn\n");
                   guessArea.setEditable(true);
              else if(message.equals("Name1"))
                   displayMessage("Enter your name.\n");
                   idField.setEditable(true);
              else if(message.equals("Name2"))
                   displayMessage("Enter your name.\n");
                   idField.setEditable(true);
              else if(message.equals("Player 2 has entered name"))
                   displayMessage("Player 2 has entered name.  Your turn\n");
                   guessArea.setEditable(true);
              else if(message.equals("Invalid guess, try again"))
                   displayMessage(message + "\n");
                   myTurn = true;
                   guessArea.setEditable(true);
              else if(message.equals("Opponent guessed"))
                   int sw = input.nextInt();
                   displayMessage("Opponent guessed " + sw);
                   sendGuess(sw);
                   displayMessage("\nOpponent moved.  Your turn.\n");
                   guessArea.setEditable(true);
              else if(message.equals("Opponent guessed and won"))
                   int sw = input.nextInt();
                   displayMessage("Opponent guessed and won with number " + sw);
                   sendGuess(sw);
                   guessArea.setEditable(false);
              else
                   displayMessage(message + "\n");
         private void displayMessage(final String messageToDisplay)
              SwingUtilities.invokeLater(
              new Runnable()
                   public void run()
                        displayArea.append(messageToDisplay);
         public void sendGuess(int guess)
              if(myTurn)
                   output.format("%d\n", guess);
                   output.flush();
         private class TextHandler implements ActionListener
         //Handles the fields
              public void actionPerformed(ActionEvent event)
                   if(event.getSource() == idField)
                        idField.setEditable(false);
                        output.format("%s\n", idField.getText());
                        output.flush();
                        myTurn = false;
                        //Sends the name to the server
                        //Sets text to the name and sets it uneditable and sets turn to false
                   if(event.getSource() == guessArea)
                        guessArea.setEditable(false);
                        output.format("%s\n", guessArea.getText());
                        output.flush();
                        guessArea.setText("");
                        myTurn = false;
                        //Send the guess to the server
                        //Clears the past guess from the screen
    import java.awt.BorderLayout;
    import java.net.ServerSocket;
    import java.net.Socket;
    import java.io.IOException;
    import java.util.*;
    import javax.swing.*;
    import java.util.concurrent.*;
    import java.util.concurrent.locks.*;
    //Imports necessary packages
    public class HostPlayer extends JFrame
    //Server class
         private JTextArea outputArea;
         private Player[] players;
         private ServerSocket server;
         private int currentPlayer;
         private final static int PLAYER_1 = 0;
         private final static int PLAYER_2 = 1;
         private final static String[] MARKS = { "1", "2"};
         private ExecutorService runGame;
         private Lock gameLock;
         private Condition otherPlayerConnected;
         private Condition otherPlayerTurn;
         private Random generator = new Random();
         private int randomNumber;
         private String p1Name, p2Name;
         //Variables
         public HostPlayer()
              super("Guessing game");
              //Title of server window
              runGame = Executors.newFixedThreadPool(2);
              //Hanldes up to two clients
              gameLock = new ReentrantLock();
              //The lock
              otherPlayerConnected = gameLock.newCondition();
              otherPlayerTurn = gameLock.newCondition();
              //The condition variables
              players = new Player[2];
              currentPlayer = PLAYER_1;
              //The players
              try
                   server = new ServerSocket(12345, 2);
              catch(IOException e)
                   e.printStackTrace();
                   System.exit(1);     
              //Establishes server
              randomNumber = generator.nextInt(10);
              //The number to be guessed 0-10
              outputArea = new JTextArea();
              add(outputArea, BorderLayout.CENTER);
              outputArea.setText("Server awaiting connections \n");
              //The output area
              displayMessage("The number is " + randomNumber + " \n");
              //Prints out what the number is
              setSize(300, 300);
              setVisible(true);
              //Sets the size of the server window
         public void execute()
              for(int i = 0; i < players.length; i++)
                   try     
                        players[i] = new Player(server.accept(), i);
                        runGame.execute(players);
                        //Runs the threads to handle clients
                   catch(IOException e)
                        e.printStackTrace();
                        System.exit(1);
              gameLock.lock();
              try
                   players[PLAYER_1].setSuspended(false);
                   otherPlayerConnected.signal();
              finally
                   gameLock.unlock();
         private void displayMessage(final String messageToDisplay)
         //Function that displays messages
              //Class + method that can update the GUI for threads
              SwingUtilities.invokeLater(
              new Runnable()
                   public void run()
                        outputArea.append(messageToDisplay);
         public boolean validateAndMove(int guess, int player)
         //Function that determines what the output should be based on the guess
              while(player != currentPlayer)
              //The player can only guess if it is his turn
                   gameLock.lock();
                   try
                        otherPlayerTurn.await();
                   catch(InterruptedException e)
                        e.printStackTrace();
                   finally
                        gameLock.unlock();
              if(correctRange(guess))
              //If the guess is a valid guess
                   currentPlayer = (currentPlayer + 1) % 2;
                   //Switches player turn
                   players[currentPlayer].otherPlayerGuessed(guess);
                   gameLock.lock();
                   try
                        otherPlayerTurn.signal();
                        //Signals other player
                   finally
                        gameLock.unlock();
                   return true;
              else
                   return false;
         public boolean correctRange(int guess)
         //Tests for a valid guess between 0-10
              if(guess >= 0 && guess <= 10)
                   return true;
              else
                   return false;
         private class Player implements Runnable
         //Player class
              private Socket connection;
              private Scanner input;
              private Formatter output;
              private int playerNumber;
              private String mark;
              private boolean suspended = true;
              private boolean game = true;
              public Player(Socket socket, int number)
                   playerNumber = number;
                   mark = MARKS[playerNumber];
                   connection = socket;
                   try
                   //Tries to get the data streams
                        input = new Scanner(connection.getInputStream());
                        output = new Formatter(connection.getOutputStream());
                   catch(IOException e)
                        e.printStackTrace();
                        System.exit(1);
              public void otherPlayerGuessed(int guess)
              //Function that detemines whether the guess is too high/low or correct
                   if(guess == randomNumber)
                        output.format("Opponent guessed and won\n");
                        output.format("%d\n", guess);
                        output.flush();
                   else
                        output.format("Opponent guessed\n");
                        output.format("%d\n", guess);
                        output.flush();
              public void run()
              //The start of the threads, at the beginning messages go back and forth to set up the connection
              //and player names
                   try
                        displayMessage("Player " + mark + "connected \n");
                        output.format("%s\n", mark);
                        output.flush();
                        //Sends the message that the player has connected
                        if(playerNumber == PLAYER_1)
                             output.format("%s\n%s", "Player 1 connected ", "Waiting for another player\n");
                             output.flush();
                             gameLock.lock();
                             try
                                  while(suspended)
                                       otherPlayerConnected.await();
                                       //Waits for player 2
                             catch(InterruptedException e)
                                  e.printStackTrace();
                             finally
                                  gameLock.unlock();
                             output.format("Name1\n");
                             output.flush();     
                             p1Name = input.nextLine();
                             displayMessage("Player 1 = " + p1Name + "\n");
                             //Sends a message to enter the name and puts the received name
                             //in the variable p1Name
                             output.format("Other player connected. Your turn.\n");
                             output.flush();
                             //Starts the game when the other player has connected
                             //A lot of the turn base is done with message handling
                             //on the client side     
                        else
                             output.format("Name2\n");
                             output.flush();
                             p2Name = input.nextLine();
                             displayMessage("Player 2 = " + p2Name + "\n");
                             output.format("Player 2 connected. Please wait.\n");
                             output.flush();
                             //Sets up player 2's name and turn
                        while(game)
                        //while the game is not over
                             int guess = 0;
                             if(input.hasNext())
                                  guess = input.nextInt();
                             }//Gets next input
                             if(validateAndMove(guess, playerNumber))
                             //Sends the correct output based on the guess
                                  if(guess < randomNumber)
                                       if(playerNumber == 0)
                                            displayMessage(" \n"+p1Name+ " guess: " + guess);
                                       else
                                            displayMessage(" \n" p2Name " guess: " + guess);
                                       output.format("Guess too low.\n");
                                       output.flush();
                                  else if(guess > randomNumber)
                                       if(playerNumber == 0)
                                            displayMessage(" \n"+p1Name+ " guess: " + guess);
                                       else
                                            displayMessage(" \n" p2Name " guess: " + guess);
                                       output.format("Guess too high.\n");
                                       output.flush();
                                  else
                                       if(playerNumber == 0)
                                            displayMessage(" \n"+p1Name+ " guess: " + guess);
                                       else
                                            displayMessage(" \n" p2Name " guess: " + guess);
                                       output.format("You Win!\n");
                                       output.flush();
                                       game = false;
                                       //Ends game
                             else
                                  output.format("Invalid guess, try again\n");
                                  output.flush();
                   finally
                        try
                             connection.close();
                        catch(IOException e)
                             e.printStackTrace();
                             System.exit(1);
              }//End run
              public void setSuspended(boolean status)
                   suspended = status;
         }//End player class
    }//End Server class
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Thanks for the response
    I think I understand what you are saying, I just want to make sure I get it fully. I need to create a separate thread that runs just my connection process to make sure that the processes actually occur? If so, how would I go about doing this?
    Thanks again

  • Server/Client applet sample code ???

    Hi to all.
    I would like to ask if possible to someone to tell me some example code to do this simple thing:
    I want an applet showing only a TextField and a button. When the user writes something on the textfield and press the button, it should send the text in the textfield to the "server", and then it should save it in a variable.
    I think there should be 2 different classes at least (server and client), but no idea in how could I make this on Java.
    So I am asking if possible for some sample code for make this.
    Thank you for the information
    John

    here is code for applet..
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    public class MyApplet extends Applet
          implements ActionListener {
      TextField tf;
      Button btn;
      public void init() {
        setLayout(null);
        tf = new TextField();
        tf.setBounds(5,5,80,20);
        btn = new Button("send message to server");
        btn.setBounds(5,30,150,20);
        btn.addActionListener(this);
        add(tf);
        add(btn);
      public void actionPerformed(ActionEvent ae) {
        sendMessage();
      void sendMessage() {
        String msg = tf.getText().trim();
        tf.setText("");
        if(msg==null) return;
        try {
          // this is using a direct socket connection..
          Socket s = new Socket("www.blah.com",80);
          ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(s.getOutputStream()));
          oos.writeObject(msg);
          oos.flush();
          ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(s.getInputStream()));
          String response = (String) ois.readObject();
          System.out.println("response received="+response);
          ois.close();
          oos.close();
          s.close();
        } catch (Exception e) {
            System.out.println("error in sendMessage:"+e);
    }here is the html code..
    <applet code=MyApplet width=180 height=55></applet>
    let me know if u need more help.
    good luck.

  • How to detect client socket shutdowns in server socket

    Hi,
    Hoping to get some help with this. I am writing this program that implements a socket server that accepts a single client socket (from a third-party system). This server receives messages from another program and writes them to the client socket. It does not read anything back from the client. However, the client (which I have no control over) disconnects and reconnects to my server at random intervals. My issue is I cannot detect when the client has disconnected (normally or due to a network failure), hence am unable to accept a fresh connection from the client. Here's my code for the server.
    ServerSocket serverSocket = null;
    Socket clientSocket = null;
    PrintWriter out = null;
    BufferedReader in = null;
    try{
              if (serverSocket == null){
                    serverSocket = new ServerSocket(4511);
         clientSocket = serverSocket.accept();
         System.out.println("Accepted client request ... ");
         out = new PrintWriter(clientSocket.getOutputStream(), true);
         in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
         System.out.println("Input / Output streams intialized ...");          
         while (true){                              
              System.out.println("Is Client Socket Closed : " + clientSocket.isClosed());
              System.out.println("Is Client Socket Connected : " + clientSocket.isConnected());
              System.out.println("Is Client Socket Bound : " + clientSocket.isBound());
              System.out.println("Is Client Socket Input Shutdown : " + clientSocket.isInputShutdown());
              System.out.println("Is Client Socket Output Shutdown : " + clientSocket.isOutputShutdown());
              System.out.println("Is Server Socket Bound : " + serverSocket.isBound());
              System.out.println("Is Server Socket Closed : " + serverSocket.isClosed());
              messageQueue = new MessageQueue(messageQueueDir+"/"+messageQueueFile);
              //get Message from Queue Head (also removes it)
              message = getQueueMessage(messageQueue);
              //format and send to Third Party System
              if (message != null){
                             out.println(formatMessage(message));
                   System.out.println("Sent to Client... ");
              //sleep
              System.out.println("Going to sleep 5 sec");
              Thread.sleep(5000);
              System.out.println("Wake up ...");
    }catch(IOException ioe){
         System.out.println("initSocketServer::IOException : " + ioe.getMessage());
    }catch(Exception e){
         System.out.println("initSocketServer::Exception : " + e.getMessage());
    }I never use the client's inputstream to read, although I have declared it here. After the client is connected (it enters the while loop), it prints the following. These values stay the same even after the client disconnects.
    Is Client Socket Closed : false
    Is Client Socket Connected : true
    Is Client Socket Bound : true
    Is Client Socket Input Shutdown : false
    Is Client Socket Output Shutdown : false
    Is Server Socket Bound : true
    Is Server Socket Closed : false
    So, basically I am looking for a condition that detects that the client is no longer connected, so that I can bring serverSocket.accept() and in and out initializations within the while loop.
    Appreciate much, thanks.

    Crossposted and answered.

  • Need help coding simple chat client/server

    I'm writing a simple chat server/client... its works fine when run on console.. but when i used Frames, AWT gui's.... it seems that the thread that is used to read the incoming message is suspended ... until i press the [send] button.. It seems to me that AWT consumes the time listening to any event.... and my thread is waiting... for the some AWT specific events to occur.....
    If your interested guys.. i'm willing to post the source code.. here.

    Try using the swing components. I think they are supposed to be more thread safe than awt. There is a tutorial for dealing with threads and swing:
    http://java.sun.com/tutorial/uiswing/overview/threads.html
    hopes this helps

  • Please tell me how to use the Simple bluetooth client server example.

    Hi i used the simple bluetooth client server example in labview 7.1. Iam getting an error saying your system does not support the network operation.  I have following doubts also.
    1. Should i pair the device before running the labview.
    2. Should i enable the file transfer wizard in the software given with the bluetooth adapter.
    Please help
    Thank you
    R.Prem kumar 
    09940446193

    Hi R.Prem,
    Could you please let me know what error code is associated with this error message? Also could you please provide a description of the setup you are currently using? Thanks!
    Best regards,
    Steven

  • SocketPermissions for Chat Server/Client Applet

    Hi,
    I've coded a chat server/client applet and found that I need to set socketpermissions when using over the net.
    I put the following line in my java.policy file under my jdk
    permission java.net.SocketPermission ":6288", "connect,accept, listen";
    but it still tells me:
    java.security.AccessControlException: access denied(java.net.SocketPermission 217.0.0.1:6288 connect, resolve)
    any ideas? or am I doing something wrong?
    Also I havent set anything for my applet, and wouldnt know how to? if you do have to set permissions for that, do you put the permissions in with the code or something?
    Thanks in advance.
    Matt.

    ah, dont worry, I've got it fixed.
    that 217.0.0.1 address is because I typed the error by the way, usually it would have my IP.
    problem was I had forgot to recompile with my new assigned IP, d'oh!

  • Need Help for client - server - client question [Sockets]

    Hi
    I have read the http://java.sun.com/docs/books/tutorial/networking/sockets/index.html tutorial and made this Knock Knock Application.
    But now, I want that one client can view all the other clients which are connected to the server, and interract with a selected cleint over the server (client - server - client).
    But I have no idea how to build such a registration concept?
    A concrete hint (or link) how to realise this would be very helpful. I searched all the internet for examples, but I dont found a simple example.
    Thanks in advance
    greeds

    wSam,
    It appears that Sun considers RMI to be simpler, although less efficient than the alternative:
    http://java.sun.com/developer/technicalArticles/ALT/sockets/
    This article also talks about object serialization, which I am a fan of. Suppose that you want to send a data structure containing lots of information (like all connected users). You can actually pass an object (rather than text) across the network using ObjectOutputStream and receive it on the other end with ObjectInputStream. You might create your own Command class for passing objects between the client and server instead of using RMI. The Command class might hold flags that indicate which method should take place on the remote machine (i.e. send chess move command).

  • Stream-in images from client to server,without running the transmit code

    Hello all,
    Im using JMF for my current project.Right now,I am trying to only recieve images from the client without the client transmitting it.That is I dont want the transmit code to run on the client.
    I should just be able to stream in the images from client to server, without running the transmit code on client.
    Can this be done?
    Thanks in advance

    suppigs wrote:
    Can I know more about this?Sure.
    <Side A>
    You'd just need to write an application that doesn't have a GUI (so, a console-based application) that listens on some pre-determined port for a message to start broadcasting. Maybe you'd send it the IP/PORT number to start broadcasting on. Once it receives that message, it'd start broadcasting the web cam to the IP/PORT number until it received a message to stop. Once it stops, it'll just go back to waiting for the next "start" signal.
    <Side B>
    On the other side, you'd write an application that sends the start messages, receives/displays the videos, and then sends the stop signal. This will have a GUI, and be your "control program" so to speak.
    Then, once of have both of those programs working...if you're using Linux, you're done. If you're using Windows, you'd need to modify the <Side A> program so that it can run as a Windows service.
    There are a lot of ways to do this, you can google it or look at the following link:
    [http://twit88.com/blog/2007/09/19/open-source-software-to-start-up-java-as-windows-serviceunix-daemon/]

  • Can Simple Data Client/Server VIs communicate between computers?

    I am having trouble using the Simple Data Client VI / Simple Data Server VI to communicate between computers? Can these VIs do this ..or do they simply communicate between each other on a single computer? TIA.

    NO it can be used between two computers. You have to replace the localhist string with the IP address of the computer running the server and make sure that the server computer is allowing external connections on the specified port.
    Regards,
    André
    Using whatever version of LV the customer requires. (LV5.1-LV2012) (www.carya.nl)

  • Need help regarding Simple Data Client and Simple Data Server VIs

    Hi everyone.
    I have a simple objective. I just want to test the 2 example VIs, "Simple Data Client" and "Simple Data Server" between 2 computers. I just want to check whether is this working between the 2 computers.
    What I have done for now is that I changed the "address", from "localhost" in the "Simple Data Client.vi" to the IP address of the computer running the "Simple Data Server". I runned the "Simple Data Server" VI in one of the computers first followed by the "Simple Data Client" in the other computer. Nothing is received and the client just timed out.
    Can anyone please help me troubleshoot and tell me what are the possible problems for this? Are there any wires connections between 2 computers that I am missing or any other configurations I have to make before I can successfully do this?
    Thanks.
    Regards,
    Jonathan

    Hi Lee.P.
    I understand that. I was just feeling frustrated about the project not working. Sincere apologies from me.
    I was wrong about the error number. It is not Error 60. It is Error 59 - The network is down, unreachable, or has been reset.. Yes, I have tried changing the port numbers at the 2 computers when trying to send/receive.
    Could anything else be the problem?
    Regards,
    Jonathan  

Maybe you are looking for

  • In popup step how do I get the "text on the button" in the report rather than button index?

    (1) How do I configure the POPUP step in "SEQ MAIN.seq" to execute the second step (IS OUT PUT IS 20?) in "SEQ 1.seq" when "IS OUT PUT IS 20?" button hit and execute the third step (IS OUT PUT IS 30?) in "SEQ 1.seq" when "IS OUT PUT IS 30?" button hi

  • Adobe Application Manager and other Installers All Messed up

    I have a Mac Pro running 10.5.8 and CS5 Design Premium. Today I noticed 3 new updates: Bridge 4.0.2, Camera Raw 6.1, and a Flash thing. I ran the update using Adobe Application Manager (AAM). It failed on all three. I tried every way I could find to

  • Trouble Opening Illustrator on CS5.5

    I am using the Design Premium cs5.5 on my mac computer. I am having trouble opening the illustrator programme. All the other programmes in the suite work but when I go to open this one it opens to the 'initialising' page and then nothing. Ive tried r

  • Odd save to PDFx1a issue

    MacPro OS 10.5.8 / AI 15.0.1 I have a file set up. Simple one color file two artboards with 18pt bleeds. I can Save As with no problem. I choose Save As PDF... Select PDFX1a from the Job Options... file saves no issue. I choose Save As PDF... Select

  • Opening an asset in back date

    Dear All:               My question is regarding opening asset master data through AS01. When we open an asset it is saved with current date. But what if we want to open it in back date. let us say today is 2nd july 2010 but i want to open an asset b