Making a Client & Server app with UDP

Hello fellahs, as the title of this post says I'm making a client and server application. The server are supposed to handel several clients, and the communication is done true UDP.
I have got two questions concerning this. The first one is if a exception is throws in the server should I then send the exception back to the client in serialized form. If I choose to do this then I also would need to handel the exception classen to the client. Or should I send back a regular IOException and use it's init cause to define the exception which occured in the server.
The second question is concerning the multi client support. If this is going to work then I would need to time-out the connection i the server environment, and I have not a clue about how long it should be?
/thanks in regards Ali.

superdeportivo wrote:
Hello fellahs, as the title of this post says I'm making a client and server application. The server are supposed to handel several clients, and the communication is done true UDP. Out of interest why have you chosen UDP rather than TCP?
I have got two questions concerning this. The first one is if a exception is throws in the server should I then send the exception back to the client in serialized form. If I choose to do this then I also would need to handel the exception classen to the client. Or should I send back a regular IOException and use it's init cause to define the exception which occured in the server. That is up to you, you can do either. I would do the first option.
The second question is concerning the multi client support. If this is going to work then I would need to time-out the connection i the server environment, and I have not a clue about how long it should be?It should be long enough that you don't timeout a valid connection. There is no simple answer to this.

Similar Messages

  • OSX: multi client server app with NSNetService

    hello
    i have a small osx server app
    that uses NSNetService to manage connection and set up streams
    but it seems to stop advertising as soon as a clients connects
    how can i make it multiclient so it keeps advertising and when a new client connects uses the same streams ?
    thanks in advance
    nonnus

    superdeportivo wrote:
    Hello fellahs, as the title of this post says I'm making a client and server application. The server are supposed to handel several clients, and the communication is done true UDP. Out of interest why have you chosen UDP rather than TCP?
    I have got two questions concerning this. The first one is if a exception is throws in the server should I then send the exception back to the client in serialized form. If I choose to do this then I also would need to handel the exception classen to the client. Or should I send back a regular IOException and use it's init cause to define the exception which occured in the server. That is up to you, you can do either. I would do the first option.
    The second question is concerning the multi client support. If this is going to work then I would need to time-out the connection i the server environment, and I have not a clue about how long it should be?It should be long enough that you don't timeout a valid connection. There is no simple answer to this.

  • Client Server Application with images or icons

    I made a Client Server application with JFrames, but I put a jLabel with an icon, and I can't run the Client.
    It says java.lang.NullPointerException
    Do you know why I can't see the icon in the JLabel? It isn't an applet, it's an application with JFrames.

    You have to explain the problem better if you want some help. Also show the code which is giving you the nullpointerexception(Do not forget codetags!).

  • Client/Server API with push?

    I set up a simple Socket client server architecture with the Java socket API. However, my clients sometimes are initiators or requests, and sometimes my server is the initiator of infos. Example: client want to get infos from server but also want to tell the server something. The server tells all registered clients something but also can accept requests from clients. So both sides are client AND server (depending on what they currently want to do).
    The socket API is just a classic client/server API, i.e. a server listens and a client sends requets and get responses. For my server to send requests to all clients, this is not enough. Is the only way to have all clients offering a socket server on their computer, too? so that this 2-way-request-communication works?
    This is basically some kind of "push" technology, but i don't want my clients to "poll" the server just to emulate the feature of sending requests from the server to the client. Is there some other (perhaps non-socket) API that offers this?

    @sjasja: how is the socket api symmetrical?It is, trust me! Connection initiation isn't, but after that it is. (Let's assume connected TCP/IP.)
    The server does bind() and accept(), the client does connect(). After that, the connection is symmetrical: either end can issue any number of read() and write() calls in any order. You write() to a socket, it pops out from read() at the other end (though not necessarily as a single packet; TCP/IP is stream oriented, so write() "packets" can and will be glued together, or fragmented at the whimsy of network routers and friends.)
    - accept() //wait for client to send request
    - socket.getInputStream() //read request
    - socket .getOutputStream() //write responseThose don't read or write; they get streams which you can read from and write to.
    In the server, when accept() returns a new connection, you'd start a reader thread for that client. The thread would read() (or readLine() if you implement a line-oriented protocol) and handle the incoming messages. Whenever you want to write to the client, write to the stream returned by socket.getOutputStream(). You may need to synchronize writes if you have several threads that do sequences of write()s that need to arrive at the client sequentially.
    As to the difficulty of socket programming: I don't think it particularly difficult. But then I've written dozens of socket programs since my first one in '85... The Java Tutorial socket chapter shows a simple client/server pair; not terribly difficult I think. In particular, check out the KKMultiServer at the bottom of the sample server chapter.

  • White Paper: End-to-End Client/Server Security with the Adobe Flash Platform

    Today we released a sorely needed white paper on end-to-end client/server security with the Adobe Flash Platform.  This information is directly applicable to the Adobe  LiveCycle family as well as Flash RIAs. 
    http://www.slinnbooks.com/books/enterprise/securityWhitePaper.shtml
    Thank you,
    Mike
    Michael Slinn
    http://micronauticsresearch.com
    http://slinnbooks.com

    Hai,
           Delete the certificate in the ABAP system and try importing the new certificate from the EP instance(ADS) and export into the ABAP and check...
    Thanks and Regards,

  • Lotus Notes Client Server Apps

    I'm wondering if anyone has tried to connect to lotus notes client server apps. from portal. I've heard that they have to be "webified" first. Is that true or are there different ways to get to the lotus notes app?

    Hi,
    Please post this on PDK forum.
    Thanks,
    Sharmila

  • How to design socket client-server app for 2-way communication

    Hi, I am writing a client-server application. I have a single server and many clients. Each client will need the ability to send information to the server at any time. The server will also need the ability to send information to a client at any time. Its this second part that I am not sure how to design. Would I need to create a SocketServer on each client to accept incoming messages, or is there a better way? Thanks

    scranchdaddy wrote:
    Don't my requirements sound a lot like an IM application, where a chat server might need to send a message to a chat client at any time?Not really. If that is what you are designing
    in my opinion one could easily be forgiven for thinking you were deliberately obfuscating your goal...
    How does the server know where the client is? Does it know the IP address of the client?I would imagine the server would contain a directory of IPs? I'm not sure.
    What happens if the client is not running?Then I guess the message would not get delivered.
    What happens if the client is behind a firewall that does not allow incoming connections?How do IM chat clients work? How have people solved this in the past?Typically the server would only care about clients currently connected to the server.
    Maybe you should re-think your design. I don't really have a design, just requirements, that's why I'm writing this post.Your subject says "+How to *design* socket client-server app for 2-way communication+".
    Are you saying you expect someone else to do the design for you?

  • Help Needed With Basic Client/Server App

    I was wondering if anyone can help with a simple blackjack client/server application i've been writting (basically its a moddified chat application). The problem i'm having seems to lie within the connection management i've written.
    What i'm trying to get is that only 4 players can connect at one time and that each player takes a turn (which i've implemented using threads) to play their hand (as you would if you were playing it for real). The problem is that it will allow the players to connect, but oddly enough, it will not allow a new transaction to be created (i.e. allow a player to take their turn) until 2 players have connected.
    Even when it does create the transaction, after taking input from the client once, the server seems to stop doing anything without any error message of any kind.
    Its really annoyed me now, so you guys are my last hope!
    The code can be found in full here:
    Client Application: http://stuweb3.cmp.uea.ac.uk/~y0241725/WinEchoClient.java
    Server Application: http://stuweb3.cmp.uea.ac.uk/~y0241725/ThreadServer.java
    Card Class: http://stuweb3.cmp.uea.ac.uk/~y0241725/Card.java
    Deck Class: http://stuweb3.cmp.uea.ac.uk/~y0241725/Deck.java
    Please feel free to play around with this code as much as you feel necessary!

    (one last bump back up the forum before i give up on this completely)

  • Integrating DOS/client server apps through portal

    Is there any partners out their that have developed any portlets that will integrate legacy client server or DOS through the portlet in a Citrix NFuse fashion?
    There seems to be a few competitive portal providers out their who claim that this can be done. OBTree does this via Java wrapped emulation software which can be integrated over the web.
    This would be very useful for legacy integration into one place without rewriting a front end etc.
    Any ideas or recommendations?

    Any one got idea how to resolve this problem. We are facing this problem with applet based applications. Pleae let me know if any one know how to write netlet rules to make this app. work through portal.

  • Push config files made in Server app with Profile manager

    As I understand the manual you can distribuate configuration files with Profile manager.
    A bit confused now when I want to use Profile manager to distribuate a configuration file I´ve made in Server app.
    I saved a VPN configuration file and want to distribuate it with Profile manager but how do I import or add that file into the settings pane for my devices in profile manager?

    Hi,
    I have the same issue, very frustrating. Using a Win 2003 AD and 10.8.2 server and clients. If i use WGM I can see all users and groups correctly, but Server.app and Profile Manager does not show them correct.
    Strange that we see issues like this since Profile Manager has been around for a while, really interested to hear other peoples experiences.
    PS I see a similar thing here: https://discussions.apple.com/thread/4417085?start=0&tstart=0

  • Client == server - problems with callbacks

    Hi everyone!
    I'm having trouble establishing bidirectional communication between a client and a server (code samples are below).
    Both classes (client & server) extend UnicastRemoteObject and implement Interfaces that are extending Remote. Now the client looks up the server and tries to register itself at the server by calling a method like this:
    remote_server.setClient(this);
    as long as I execute both programs in the same LAN this method-call works fine, but when client and server connect through internet I'm getting the following exception:
    ---------------------- Exception ------------------------>
    java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
         java.rmi.ConnectException: Connection refused to host: 192.168.0.3; nested exception is:
         java.net.ConnectException: Connection timed out
         at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:292)
    <---------------------- Exception ------------------------
    maybe helpful:
    - 192.168.0.3 is the client's LAN-IP
    - I am directly connected to the internet via ADSL-modem (no router)
    I searched the forums for several hours now, I read through the following tutorial,
    http://developer.java.sun.com/developer/onlineTraining/rmi/exercises/RMICallback/index.html
    but still I didn't find a solution.
    I already spent a lot of time developing this and I start to get desperate, so I hope someone of you out there can help me!
    pilord
    ==================== Codesamples =======================>
    public class ServerImpl extends UnicastRemoteObject implements Server {
    Client client;
    public ServerImpl() {
    LocateRegistry.getRegistry(1096).rebind("test",this);
    /* specified in Remote-Interface: Server*/
    public void setClient(Client client) {
    this.client = client;
    public class ClientImpl extends UnicastRemoteObject implements Client {
    public ClientImpl() {
    Server s = Naming.lookup("rmi://***.***.***.***:1096/test");
    s.setClient(this); // HERE is the trouble.
    <==================== Codesamples =======================

    Don't feel lost, crumb. Http tunnelling is not as complex as it seems. I just started using RMI at my new job here and in a couple of weeks I've already picked up on alot of what I needed to know. (I just posted a question myself on the same topic.) Basically what you have to do is set up a web server for RMI to talk to at the server side. It will work if the webserver is listening on port 80 with the rmiservlet.ServletHandler registered to respond to any path request of cgi-bin/java-rmi.cgi. In other words "cgi-bin/java-rmi.cgi" should be the servlet-mapping of the ServletHandler. The servlet merly acts as a proxy on behalf of the RMI client and fowards the request to the desired port on the server. If you know how to set up a servlet as the default web app then it is really a breeze. On the client side you only need to set the http.proxyHost and http.proxyPort system properties to the appropriate values for your proxy server. (I mistyped these property names in my prior post use what I have here as I just read it out of the RMI book.) Do a search on HTTP tunnelling and you should turn up dozens of hits. I have the source to the servlet if you need it. I've already modified it for my own purposes though it should still work for you. If you forego http tunnelling then you'll have to do a complete app rewrite to use another protocol because RMI just doesn't work through firewalls without it. Alternatively you can get down and dirty with some low level sockets coding (this is what I'm thinking I'll end up doing eventually) to get it working without standard RMI/HTTP but that's way more complex. Unfortunately it looks like your callback code will need to be rewritten unless you either go commercial or do the socket stuff. (There does seem to be a shareware product called rmi doves that would help you here.) I'll be happy to assits you in any way as you need help.
    Cliff

  • Creating chart in java client/server app.

    Currently, I'm developing a client/server java app. under windows. I want to create a chart (pie, bar) for graphically reporting, anybody can help me pls........? Thanks a lot
    TriAK

    There are some solutions...You can use the Java Chart() class or BarChart() from the J2sdk API.
    (http://java.sun.com/applets/jdk/1.4/demo/applets/BarChart/example1.html)
    Besides, you can use some already build class from some companies like ObjectPlanet.(www.objectplanet.com).
    There is also another link(have a look at it) http://www.java4less.com/charts_e.htm
    Another way is to build by your own using java.awt(It will be to most difficult in the manner of time consumed).
    Finally, I will recommend you to create charts as html page integrate this application as Applet or html in general(Javascript,JSP).
    I hope I gave you some ideas.

  • Client server code with errors could some one please help me!!!

    I am using a random access file to design the two interfaces for my client and my server is this the right thing to do? Oh could some one give me some example code of client server interfaces.
    I got an error in the code for the interfaces and I don't know what it is could some one please help me!!
    Heres the error in the code: This is for RegisterCustomer
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    class RegisterCustomer extends JPanel implements ActionListener
    // Button for registering a customer
    private JButton jbtRegister;
    // Customer information panel
    private CustomerPanel customerPanel; (The error is on this line and it says Field type customer panel is missing)
    // Random access file
    private RandomAccessFile raf;
    Second error: Its in the ViewCustomer:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    // View customer panel
    class ViewCustomer extends JPanel implements ActionListener
    // Buttons for viewing customer information
    private JButton jbtFirst, jbtNext, jbtPrevious, jbtLast;
    // Random access file
    private RandomAccessFile raf = null;
    // Current customer record
    private Customer customer = new Customer();
    // Create a customer panel
    private CustomerPanel customerPanel = new customerPanel(); (its on this line and it says field type CustomerPanel is missing)
    // File pointer in the random access file
    private long lastPos;
    private long currentPos;
    Heres the code for the customerPanel:
    // Customer Panel.java: Panel for displaying Customer information
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.*;
    public class customerPanel extends JPanel
         JTextField jtfRegistrationnumber = new JTextField(30);
         JTextField jtfSeatingcapacity = new JTextField(20);
    JTextField jtfStartdateofhire = new JTextField(20);
    JTextField jtfDurationofhire = new JTextField(10);
    JTextField jtfManufacture = new JTextField(20);
    JTextField jtfModel = new JTextField(15);
         JTextField jtfEnginesize = new JTextField(15);
    JTextField jtfCharge = new JTextField(20);
    JTextField jtfMileage = new JTextField(10);
    // Constuct a customer panel
    public customerPanel()
    // Set the panel with line border
    setBorder(new BevelBorder(BevelBorder.RAISED));
    // Panel p1 for holding all the labels
    JPanel p1 = new JPanel();
    p1.setLayout(new GridLayout(3, 1));
    p1.add(new JLabel("Registration number"));
    p1.add(new JLabel("Seating capacity"));
    p1.add(new JLabel("Start date of hire"));
    p1.add(new JLabel("Duration of hire"));
    p1.add(new JLabel("Manufacture"));
    p1.add(new JLabel("Model"));
    p1.add(new JLabel("Engine size"));
    p1.add(new JLabel("Charge"));
    p1.add(new JLabel("Mileage"));
    // Panel jpRegistration number for registration number
    JPanel jpRegistrationnumber = new JPanel();
    jpRegistrationnumber.setLayout(new BorderLayout());
    jpRegistrationnumber.add(new JLabel("Registration number"), BorderLayout.WEST);
    jpRegistrationnumber.add(jtfRegistrationnumber, BorderLayout.CENTER);
    // Panel jpSeating capacity for holding Seating capacity
    JPanel jpSeatingcapacity = new JPanel();
    jpSeatingcapacity.setLayout(new BorderLayout());
    jpSeatingcapacity.add(new JLabel("Seating capacity"), BorderLayout.WEST);
    jpSeatingcapacity.add(jtfSeatingcapacity, BorderLayout.CENTER);
         // Panel jpStart date of hire for holding start date of hire
    JPanel jpStartdateofhire = new JPanel();
    jpStartdateofhire.setLayout(new BorderLayout());
    jpStartdateofhire.add(new JLabel("Start date of hire"), BorderLayout.WEST);
    jpStartdateofhire.add(jtfStartdateofhire, BorderLayout.CENTER);
    // Panel jpDuration of hire for holding Duration of hire
    JPanel jpDurationofhire = new JPanel();
    jpDurationofhire.setLayout(new BorderLayout());
    jpDurationofhire.add(new JLabel("Duration of hire"), BorderLayout.WEST);
    jpDurationofhire.add(jtfDurationofhire, BorderLayout.CENTER);
    // Panel p2 for holding jpRegistration number and jpSeating capacity and start date of hire and duration of hire
    JPanel p2 = new JPanel();
    p2.setLayout(new BorderLayout());
    p2.add(jpRegistrationnumber, BorderLayout.WEST);
    p2.add(jpSeatingcapacity, BorderLayout.CENTER);
    p2.add(jpStartdateofhire, BorderLayout.CENTER);
    p2.add(jpDurationofhire, BorderLayout.CENTER);
    // Panel p3 for holding jtfManufacture and p2
    JPanel p3 = new JPanel();
    p3.setLayout(new BorderLayout());
    p3.add(jtfManufacture, BorderLayout.CENTER);
    p3.add(p2, BorderLayout.EAST);
    // Panel p4 for holding jtfModel, jtfEngine size, charge and mileage and p3
    JPanel p4 = new JPanel();
    p4.setLayout(new GridLayout(3, 1));
    p4.add(jtfModel);
    p4.add(jtfEnginesize);
    p4.add(jtfCharge);
    p4.add(jtfMileage);
    p4.add(p3);
    // Place p1 and p4 into customerPanel
    setLayout(new BorderLayout());
    add(p1, BorderLayout.WEST);
    add(p4, BorderLayout.CENTER);
    // Get customer information from the text fields
    public Customer getCustomer()
    return new Customer(jtfRegistrationnumber.getText().trim(),
                             jtfSeatingcapacity.getText().trim(),
                                  jtfStartdateofhire.getText().trim(),
                             jtfDurationofhire.getText().trim(),
                             jtfManufacture.getText().trim(),
                             jtfModel.getText().trim(),
                                  jtfEnginesize.getText().trim(),
                             jtfCharge.getText().trim(),
                             jtfMileage.getText().trim());
    // Set customer information on the text fields
    public void setCustomer(Customer s)
    jtfRegistrationnumber.setText(s.getRegistrationnumber());
    jtfSeatingcapacity.setText(s.getSeatingcapacity());
    jtfStartdateofhire.setText(s.getStartdateofhire());
    jtfDurationofhire.setText(s.getDurationofhire());
    jtfManufacture.setText(s.getManufacture());
    jtfModel.setText(s.getModel());
    jtfEnginesize.setText(s.getEnginesize());
    jtfCharge.setText(s.getCharge());
    jtfMileage.setText(s.getMileage());
    Could someone please help me and tell me what these two errors mean and how I could get rid of them

    Can some one take a look at this code and tell me how to get all my jlabels to line up alone side their jtf.
    Because it looks like this the picture in the attached file and this is the code for it:
    public customerPanel()
    // Set the panel with line border
    setBorder(new BevelBorder(BevelBorder.RAISED));
    // Panel p1 for holding labels Name, Street, and City
    JPanel p1 = new JPanel();
    p1.setLayout(new GridLayout(5, 1));
    p1.add(new JLabel("Registration Number:"));
    p1.add(new JLabel("Seating Capacity:"));
    p1.add(new JLabel("Engine Size:"));
    p1.add(new JLabel("Start date of hire"));
    p1.add(new JLabel("Duration of hire"));
    JPanel p2 = new JPanel();
    p2.setLayout(new GridLayout(5, 1));
    p2.add(jtfRegistrationnumber);
    p2.add(jtfSeatingcapacity);
    p2.add(jtfEnginesize);
    p2.add(jtfStartdateofhire);
    p2.add(jtfDurationofhire);
    //JPanel p3 = new JPanel();
    //p3.add(p1, BorderLayout.WEST);
    //p3.add(p2, BorderLayout.NORTH);
    JPanel p4 = new JPanel();
    p4.setLayout(new GridLayout(4, 1));
    p4.add(new JLabel("Manufacture:"));
    p4.add(new JLabel("Model:"));
    p4.add(new JLabel("Mileage:"));
    p4.add(new JLabel("Charge:"));
    JPanel p5 = new JPanel();
    p5.setLayout(new GridLayout(4, 1));
    p5.add(jtfManufacture);
    p5.add(jtfModel);
    p5.add(jtfMileage);
    p5.add(jtfCharge);
    // JPanel p6 = new JPanel();
    // p6.setLayout(new BorderLayout());
    // p6.add(p4, BorderLayout.SOUTH);
    // p6.add(p5, BorderLayout.EAST);
    // Place p1 and p4 into CustomerPanel
    setLayout(new BorderLayout());
    add(p1, BorderLayout.WEST);
    add(p2, BorderLayout.NORTH);
    add(p4, BorderLayout.SOUTH);
    add(p5, BorderLayout.EAST);
    So could someone please help me and correct my code so that each text lable is lined up next to its jtf java text field.

  • 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

  • Client Server Socket With GUI

    Hi,
    As the name of the forum suggests I am very new to this whole thing.
    I am trying to write a client/server socket program that can encrypt and decrypt and has a GUI, can't use JCE or SSL or any built in encryption tools.
    I have the code for everything cept the encryption part.
    Any help, greatly appreciated,

    tnks a million but how do i incorporate that into the following client and server code:
    here's the client code:
    import java.awt.Color;
    import java.awt.BorderLayout;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    import java.net.*;
    class SocketClient extends JFrame
              implements ActionListener {
    JLabel text, clicked;
    JButton button;
    JPanel panel;
    JTextField textField;
    Socket socket = null;
    PrintWriter out = null;
    BufferedReader in = null;
    SocketClient(){ //Begin Constructor
    text = new JLabel("Text to send over socket:");
    textField = new JTextField(20);
    button = new JButton("Click Me");
    button.addActionListener(this);
    panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.setBackground(Color.white);
    getContentPane().add(panel);
    panel.add("North", text);
    panel.add("Center", textField);
    panel.add("South", button);
    } //End Constructor
    public void actionPerformed(ActionEvent event){
    Object source = event.getSource();
    if(source == button){
    //Send data over socket
    String text = textField.getText();
    out.println(text);
         textField.setText(new String(""));
    //Receive text from server
    try{
         String line = in.readLine();
    System.out.println("Text received :" + line);
    } catch (IOException e){
         System.out.println("Read failed");
         System.exit(1);
    public void listenSocket(){
    //Create socket connection
    try{
    socket = new Socket("HUGHESAN", 4444);
    out = new PrintWriter(socket.getOutputStream(), true);
    in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    } catch (UnknownHostException e) {
    System.out.println("Unknown host: HUGHESAN.eng");
    System.exit(1);
    } catch (IOException e) {
    System.out.println("No I/O");
    System.exit(1);
    public static void main(String[] args){
    SocketClient frame = new SocketClient();
         frame.setTitle("Client Program");
    WindowListener l = new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    frame.addWindowListener(l);
    frame.pack();
    frame.setVisible(true);
         frame.listenSocket();
    SERVER Code
    import java.awt.Color;
    import java.awt.BorderLayout;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    import java.net.*;
    class SocketServer extends JFrame
              implements ActionListener {
    JButton button;
    JLabel label = new JLabel("Text received over socket:");
    JPanel panel;
    JTextArea textArea = new JTextArea();
    ServerSocket server = null;
    Socket client = null;
    BufferedReader in = null;
    PrintWriter out = null;
    String line;
    SocketServer(){ //Begin Constructor
    button = new JButton("Click Me");
    button.addActionListener(this);
    panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.setBackground(Color.white);
    getContentPane().add(panel);
    panel.add("North", label);
    panel.add("Center", textArea);
    panel.add("South", button);
    } //End Constructor
    public void actionPerformed(ActionEvent event) {
    Object source = event.getSource();
    if(source == button){
    textArea.setText(line);
    public void listenSocket(){
    try{
    server = new ServerSocket(4444);
    } catch (IOException e) {
    System.out.println("Could not listen on port 4444");
    System.exit(-1);
    try{
    client = server.accept();
    } catch (IOException e) {
    System.out.println("Accept failed: 4444");
    System.exit(-1);
    try{
    in = new BufferedReader(new InputStreamReader(client.getInputStream()));
    out = new PrintWriter(client.getOutputStream(), true);
    } catch (IOException e) {
    System.out.println("Accept failed: 4444");
    System.exit(-1);
    while(true){
    try{
    line = in.readLine();
    //Send data back to client
    out.println(line);
    } catch (IOException e) {
    System.out.println("Read failed");
    System.exit(-1);
    protected void finalize(){
    //Clean up
    try{
    in.close();
    out.close();
    server.close();
    } catch (IOException e) {
    System.out.println("Could not close.");
    System.exit(-1);
    public static void main(String[] args){
    SocketServer frame = new SocketServer();
         frame.setTitle("Server Program");
    WindowListener l = new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    frame.addWindowListener(l);
    frame.pack();
    frame.setVisible(true);
         frame.listenSocket();
    Again help on this is very welcomed

Maybe you are looking for