Client-Server programm creation
Hi.
Im creating a client-server programm, in which the server has to only send a requested file by the client. Im having problems on specifying the file.. i tried, but had no luck. The server can handle multiple connections (or at least should). As fas as i have understood, i should make the client send the file name of interest of the server, and then, the server should send the file. The client has a GUI, its code is here too.
How does everything look overall?
The server part.
MyServer code:
Code :
import java.net.*;
import java.io.*;
class SendData implements Runnable
{
String location="studenti02.txt";
Socket newCon;
MyClient client;
SendData(Socket newCon)
{
this.newCon=newCon;
System.out.println("Thread started!");
run();
}
public void run()
{
try
{
System.out.println("Using port: "+newCon.getPort());
System.out.println("Adress: "+ newCon.getInetAddress().getHostAddress());
File file=new File(location);
byte [] bytearray=new byte[(int)file.length()];
FileInputStream fileInput = new FileInputStream(file);
BufferedInputStream bufferedIn=new BufferedInputStream(fileInput);
bufferedIn.read(bytearray,0,bytearray.length);
OutputStream out= newCon.getOutputStream();
out.write(bytearray,0,bytearray.length);
out.flush();
out.close();
bufferedIn.close();
newCon.close();
}
catch(IOException e)
{
System.out.println(e.getStackTrace());
}
}
}
public class MyServer {
int port;
String location;
ServerSocket socket=null;
MyServer(int port)
{
this.port=port;
System.out.println("Server started");
try
{
socket=new ServerSocket(port);
}
catch(IOException e)
{
System.out.println(e.getStackTrace());
}
while(true)
{
try
{
Socket newCon=socket.accept();
SendData conection=new SendData(newCon);
}
catch(IOException er)
{
System.out.println(er.getStackTrace());
}
}
}
public static void main(String[] args)
{
MyServer server=new MyServer(1999);
}
}
MyClient Code:
Code :
import java.net.*;
import java.io.*;
public class MyClient {
ClientFrame window;
ErrorMessage err;
String host;
int port;
int filesize=6022386;
int bytesRead;
int current=0;
Socket server;
MyClient()
{
System.out.println("Client started");
}
public void serverCheck()
{
server.isConnected();
}
public void setHost(String host)
{
this.host=host;
}
public void setPort(int port)
{
this.port=port;
}
public void RecieveFile()
{
try
{
Socket server=new Socket(host, port);
server.setSoTimeout(1000);
byte [] bytearray=new byte[filesize];
InputStream input=server.getInputStream();
FileOutputStream out=new FileOutputStream("data.txt");
BufferedOutputStream buffer=new BufferedOutputStream(out);
bytesRead = input.read(bytearray,0,bytearray.length);
current=bytesRead;
do
{
bytesRead=input.read(bytearray,current,(bytearray.length-current));
if(bytesRead>=0) current+=bytesRead;
}while(bytesRead>-1);
buffer.write(bytearray,0,current);
buffer.flush();
buffer.close();
server.close();
}
catch(ConnectException b)
{
err=new ErrorMessage("Could not connect", "Bug found", window);
err.setVisible(true);
}
catch(IOException e)
{
err=new ErrorMessage("Something is wrong..", "Bug found", window);
err.setVisible(true);
}
}
public static void main(String[] args)
{
MyClient client=new MyClient();
ClientFrame frame=new ClientFrame(client);
}
}
ClientFrame Code:
Code :
package mess;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.*;
@SuppressWarnings("serial")
public class ClientFrame extends JFrame
{
ErrorMessage dialog;
private JTextField host;
private JTextField socket;
private JTextField file;
private JButton button;
private MyClient client;
ClientFrame(MyClient client)
{
this.client=client;
StartUI();
}
public void StartUI()
{
setTitle("Client");
JPanel textPanel=new JPanel(new GridLayout(3,1));
add(textPanel, BorderLayout.CENTER);
JPanel info=new JPanel(new GridLayout(3,1));
add(info, BorderLayout.WEST);
host=new JTextField(20);
JTextField hostLabel=new JTextField("Host");
hostLabel.setEditable(false);
hostLabel.setBorder(new EmptyBorder(3,3,3,3));
socket=new JTextField(20);
JTextField socketLabel=new JTextField("Socket");
socketLabel.setEditable(false);
socketLabel.setBorder(new EmptyBorder(3,3,3,3));
file=new JTextField(30);
JTextField fileLabel=new JTextField("File");
fileLabel.setEditable(false);
fileLabel.setBorder(new EmptyBorder(3,3,3,3));
textPanel.add(host);
textPanel.add(socket);
textPanel.add(file);
info.add(hostLabel);
info.add(socketLabel);
info.add(fileLabel);
button=new JButton("Request");
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(host.getText().equals("") || socket.getText().equals("") || file.getText().equals(""))
{
dialog=new ErrorMessage(" Something is missing! ","Excuse me, but..", null);
dialog.setVisible(true);
}
else
{
try
{
client.setHost(host.getText());
client.setPort(Integer.parseInt(socket.getText()));
client.RecieveFile();
}
catch(NumberFormatException eror)
{
dialog=new ErrorMessage("Do you know how to use this?","I have to ask..", null);
dialog.setVisible(true);
}
}
}
});
JPanel butPan=new JPanel();
add(butPan, BorderLayout.EAST);
butPan.add(button, BorderLayout.NORTH);
setLocationRelativeTo(null);
pack();
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
ErrorMessage Code:
Code :
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.*;
public class ErrorMessage extends JDialog
{
String message;
String windowMes;
ClientFrame parent;
JTextField errorMes;
public void Start()
{
JPanel forMessage=new JPanel();
add(forMessage, BorderLayout.CENTER);
errorMes=new JTextField();
errorMes.setText(message);
errorMes.setEditable(false);
errorMes.setBorder(new EmptyBorder(10,10,10,10));
forMessage.add(errorMes);
JPanel forButton=new JPanel();
add(forButton, BorderLayout.SOUTH);
JButton ok=new JButton("Ok");
ok.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
setVisible(false);
}
});
forButton.add(ok);
pack();
setLocationRelativeTo(null);
}
ErrorMessage(String message, String windowMes, ClientFrame parent)
{
super(parent, windowMes,true);
this.message=message;
Start();
}
}
Re: Client-Server programm creation
Quote:
Im having problems on specifying the file.
Please explain what the problem is.
What happens when you execute the code now?
You need to post code that will compile if you want anyone to test it.
The posted code is missing import statements and won't compile.
Re: Client-Server programm creation
Hi.
Im creating a client-server programm, in which the server has to only send a requested file by the client. Im having problems on specifying the file.. i tried, but had no luck. The server can handle multiple connections (or at least should). As fas as i have understood, i should make the client send the file name of interest of the server, and then, the server should send the file. The client has a GUI, its code is here too.
How does everything look overall?
The server part.
MyServer code:
Code :
import java.net.*;
import java.io.*;
class SendData implements Runnable
{
String location="studenti02.txt";
Socket newCon;
MyClient client;
SendData(Socket newCon)
{
this.newCon=newCon;
System.out.println("Thread started!");
run();
}
public void run()
{
try
{
System.out.println("Using port: "+newCon.getPort());
System.out.println("Adress: "+ newCon.getInetAddress().getHostAddress());
File file=new File(location);
byte [] bytearray=new byte[(int)file.length()];
FileInputStream fileInput = new FileInputStream(file);
BufferedInputStream bufferedIn=new BufferedInputStream(fileInput);
bufferedIn.read(bytearray,0,bytearray.length);
OutputStream out= newCon.getOutputStream();
out.write(bytearray,0,bytearray.length);
out.flush();
out.close();
bufferedIn.close();
newCon.close();
}
catch(IOException e)
{
System.out.println(e.getStackTrace());
}
}
}
public class MyServer {
int port;
String location;
ServerSocket socket=null;
MyServer(int port)
{
this.port=port;
System.out.println("Server started");
try
{
socket=new ServerSocket(port);
}
catch(IOException e)
{
System.out.println(e.getStackTrace());
}
while(true)
{
try
{
Socket newCon=socket.accept();
SendData conection=new SendData(newCon);
}
catch(IOException er)
{
System.out.println(er.getStackTrace());
}
}
}
public static void main(String[] args)
{
MyServer server=new MyServer(1999);
}
}
MyClient Code:
Code :
import java.net.*;
import java.io.*;
public class MyClient {
ClientFrame window;
ErrorMessage err;
String host;
int port;
int filesize=6022386;
int bytesRead;
int current=0;
Socket server;
MyClient()
{
System.out.println("Client started");
}
public void serverCheck()
{
server.isConnected();
}
public void setHost(String host)
{
this.host=host;
}
public void setPort(int port)
{
this.port=port;
}
public void RecieveFile()
{
try
{
Socket server=new Socket(host, port);
server.setSoTimeout(1000);
byte [] bytearray=new byte[filesize];
InputStream input=server.getInputStream();
FileOutputStream out=new FileOutputStream("data.txt");
BufferedOutputStream buffer=new BufferedOutputStream(out);
bytesRead = input.read(bytearray,0,bytearray.length);
current=bytesRead;
do
{
bytesRead=input.read(bytearray,current,(bytearray.length-current));
if(bytesRead>=0) current+=bytesRead;
}while(bytesRead>-1);
buffer.write(bytearray,0,current);
buffer.flush();
buffer.close();
server.close();
}
catch(ConnectException b)
{
err=new ErrorMessage("Could not connect", "Bug found", window);
err.setVisible(true);
}
catch(IOException e)
{
err=new ErrorMessage("Something is wrong..", "Bug found", window);
err.setVisible(true);
}
}
public static void main(String[] args)
{
MyClient client=new MyClient();
ClientFrame frame=new ClientFrame(client);
}
}
ClientFrame Code:
Code :
package mess;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.*;
@SuppressWarnings("serial")
public class ClientFrame extends JFrame
{
ErrorMessage dialog;
private JTextField host;
private JTextField socket;
private JTextField file;
private JButton button;
private MyClient client;
ClientFrame(MyClient client)
{
this.client=client;
StartUI();
}
public void StartUI()
{
setTitle("Client");
JPanel textPanel=new JPanel(new GridLayout(3,1));
add(textPanel, BorderLayout.CENTER);
JPanel info=new JPanel(new GridLayout(3,1));
add(info, BorderLayout.WEST);
host=new JTextField(20);
JTextField hostLabel=new JTextField("Host");
hostLabel.setEditable(false);
hostLabel.setBorder(new EmptyBorder(3,3,3,3));
socket=new JTextField(20);
JTextField socketLabel=new JTextField("Socket");
socketLabel.setEditable(false);
socketLabel.setBorder(new EmptyBorder(3,3,3,3));
file=new JTextField(30);
JTextField fileLabel=new JTextField("File");
fileLabel.setEditable(false);
fileLabel.setBorder(new EmptyBorder(3,3,3,3));
textPanel.add(host);
textPanel.add(socket);
textPanel.add(file);
info.add(hostLabel);
info.add(socketLabel);
info.add(fileLabel);
button=new JButton("Request");
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(host.getText().equals("") || socket.getText().equals("") || file.getText().equals(""))
{
dialog=new ErrorMessage(" Something is missing! ","Excuse me, but..", null);
dialog.setVisible(true);
}
else
{
try
{
client.setHost(host.getText());
client.setPort(Integer.parseInt(socket.getText()));
client.RecieveFile();
}
catch(NumberFormatException eror)
{
dialog=new ErrorMessage("Do you know how to use this?","I have to ask..", null);
dialog.setVisible(true);
}
}
}
});
JPanel butPan=new JPanel();
add(butPan, BorderLayout.EAST);
butPan.add(button, BorderLayout.NORTH);
setLocationRelativeTo(null);
pack();
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
ErrorMessage Code:
Code :
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.*;
public class ErrorMessage extends JDialog
{
String message;
String windowMes;
ClientFrame parent;
JTextField errorMes;
public void Start()
{
JPanel forMessage=new JPanel();
add(forMessage, BorderLayout.CENTER);
errorMes=new JTextField();
errorMes.setText(message);
errorMes.setEditable(false);
errorMes.setBorder(new EmptyBorder(10,10,10,10));
forMessage.add(errorMes);
JPanel forButton=new JPanel();
add(forButton, BorderLayout.SOUTH);
JButton ok=new JButton("Ok");
ok.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
setVisible(false);
}
});
forButton.add(ok);
pack();
setLocationRelativeTo(null);
}
ErrorMessage(String message, String windowMes, ClientFrame parent)
{
super(parent, windowMes,true);
this.message=message;
Start();
}
}
Client-Server creation FIX
Sorry about the double thread, i edited the previous and it all just disapeared..
Im writing a server-client program, the server has to send the file the client requests and im not sure how to make that request. The program works (how well is it written?), but the client recieves a frandom file, havent figured out the mechanism for the request. I tried making two funcktions, one for each side. When the server starts, it waits for a connection, then creates a thread that launches a function, to recieve the filename. The client on the other hand, startp up, you enter the desired server, port and filename, then it connects, afterwards sends the file name, then read the file. This DID NOT WORK, possible because the logic it self was wrong, or i just dont know how to hndle these kinds of situations. The socket was opened with the function, and closed after recieving the file. As far as i have googled, it has to do soemthing with that i have to tell when to stop reading.. I really hope that some one can help me, the deadline was cut by two weeks, so this has to be done by the 14th :\
The code is below, MyServer:
Code :
package mess;
import java.net.*;
import java.io.*;
class SendData implements Runnable
{
String location="studenti02.txt";
Socket newCon;
MyClient client;
SendData(Socket newCon)
{
this.newCon=newCon;
System.out.println("Thread started!");
run();
}
public void run()
{
try
{
System.out.println("Using port: "+newCon.getPort());
System.out.println("Adress: "+ newCon.getInetAddress().getHostAddress());
File file=new File(location);
byte [] bytearray=new byte[(int)file.length()];
FileInputStream fileInput = new FileInputStream(file);
BufferedInputStream bufferedIn=new BufferedInputStream(fileInput);
bufferedIn.read(bytearray,0,bytearray.length);
OutputStream out= newCon.getOutputStream();
out.write(bytearray,0,bytearray.length);
out.flush();
out.close();
bufferedIn.close();
newCon.close();
}
catch(IOException e)
{
System.out.println(e.getStackTrace());
}
}
}
public class MyServer {
int port;
String location;
ServerSocket socket=null;
MyServer(int port)
{
this.port=port;
System.out.println("Server started");
try
{
socket=new ServerSocket(port);
}
catch(IOException e)
{
System.out.println(e.getStackTrace());
}
while(true)
{
try
{
Socket newCon=socket.accept();
SendData conection=new SendData(newCon);
}
catch(IOException er)
{
System.out.println(er.getStackTrace());
}
}
}
public static void main(String[] args)
{
MyServer server=new MyServer(1999);
}
}
MyClient:
Code :
package mess;
import java.net.*;
import java.io.*;
public class MyClient {
ClientFrame window;
ErrorMessage err;
String host;
int port;
int filesize=6022386;
int bytesRead;
int current=0;
Socket server;
MyClient()
{
System.out.println("Client started");
}
public void serverCheck()
{
server.isConnected();
}
public void setHost(String host)
{
this.host=host;
}
public void setPort(int port)
{
this.port=port;
}
public void RecieveFile()
{
try
{
Socket server=new Socket(host, port);
server.setSoTimeout(1000);
byte [] bytearray=new byte[filesize];
InputStream input=server.getInputStream();
FileOutputStream out=new FileOutputStream("data.txt");
BufferedOutputStream buffer=new BufferedOutputStream(out);
bytesRead = input.read(bytearray,0,bytearray.length);
current=bytesRead;
do
{
bytesRead=input.read(bytearray,current,(bytearray.length-current));
if(bytesRead>=0) current+=bytesRead;
}while(bytesRead>-1);
buffer.write(bytearray,0,current);
buffer.flush();
buffer.close();
server.close();
}
catch(ConnectException b)
{
err=new ErrorMessage("Could not connect", "Bug found", window);
err.setVisible(true);
}
catch(IOException e)
{
err=new ErrorMessage("Something is wrong..", "Bug found", window);
err.setVisible(true);
}
}
public static void main(String[] args)
{
MyClient client=new MyClient();
ClientFrame frame=new ClientFrame(client);
}
}
ClientFrame:
Code :
package mess;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.*;
@SuppressWarnings("serial")
public class ClientFrame extends JFrame
{
ErrorMessage dialog;
private JTextField host;
private JTextField socket;
private JTextField file;
private JButton button;
private MyClient client;
ClientFrame(MyClient client)
{
this.client=client;
StartUI();
}
public void StartUI()
{
setTitle("Client");
JPanel textPanel=new JPanel(new GridLayout(3,1));
add(textPanel, BorderLayout.CENTER);
JPanel info=new JPanel(new GridLayout(3,1));
add(info, BorderLayout.WEST);
host=new JTextField(20);
JTextField hostLabel=new JTextField("Host");
hostLabel.setEditable(false);
hostLabel.setBorder(new EmptyBorder(3,3,3,3));
socket=new JTextField(20);
JTextField socketLabel=new JTextField("Socket");
socketLabel.setEditable(false);
socketLabel.setBorder(new EmptyBorder(3,3,3,3));
file=new JTextField(30);
JTextField fileLabel=new JTextField("File");
fileLabel.setEditable(false);
fileLabel.setBorder(new EmptyBorder(3,3,3,3));
textPanel.add(host);
textPanel.add(socket);
textPanel.add(file);
info.add(hostLabel);
info.add(socketLabel);
info.add(fileLabel);
button=new JButton("Request");
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(host.getText().equals("") || socket.getText().equals("") || file.getText().equals(""))
{
dialog=new ErrorMessage(" Something is missing! ","Excuse me, but..", null);
dialog.setVisible(true);
}
else
{
try
{
client.setHost(host.getText());
client.setPort(Integer.parseInt(socket.getText()));
client.RecieveFile();
}
catch(NumberFormatException eror)
{
dialog=new ErrorMessage("Do you know how to use this?","I have to ask..", null);
dialog.setVisible(true);
}
}
}
});
JPanel butPan=new JPanel();
add(butPan, BorderLayout.EAST);
butPan.add(button, BorderLayout.NORTH);
setLocationRelativeTo(null);
pack();
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
ErrorMessage:
Code :
package mess;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.*;
public class ErrorMessage extends JDialog
{
String message;
String windowMes;
ClientFrame parent;
JTextField errorMes;
public void Start()
{
JPanel forMessage=new JPanel();
add(forMessage, BorderLayout.CENTER);
errorMes=new JTextField();
errorMes.setText(message);
errorMes.setEditable(false);
errorMes.setBorder(new EmptyBorder(10,10,10,10));
forMessage.add(errorMes);
JPanel forButton=new JPanel();
add(forButton, BorderLayout.SOUTH);
JButton ok=new JButton("Ok");
ok.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
setVisible(false);
}
});
forButton.add(ok);
pack();
setLocationRelativeTo(null);
}
ErrorMessage(String message, String windowMes, ClientFrame parent)
{
super(parent, windowMes,true);
this.message=message;
Start();
}
}
Re: Client-Server programm creation
The threads have been merged
Quote:
the client recieves a frandom file,
Can you explain what that means? Try testing by sending a small file with a simple content that is easily verified. Say one or two lines with simple text like: "AAAAAAAAAAAAAAAAA"
For testing the dialog window's textfields should all be preloaded so the user does not have to stop and type anything, but only has to press the button.
Re: Client-Server programm creation
It means, that it can send a server specified file. The file sends, all is well, tried sending a picture even.
I have to edit, so that the server send a client specified file, aka i ahev to edit the server variable "location", which now is se to be "studenti02.txt".
Am asking for ideas on how to be abe to change that variable from the client..
Re: Client-Server programm creation
Quote:
server send a client specified file
Have the client send the name of the file it wants to the server. The server should read the name sent by the client and test if the file is available. If the file is found, read and send it to the client. If not available, send an error message to the client. The server's message to the client will need a header to say if there is a file being sent or an error message.
Re: Client-Server programm creation
Thanks, but i had that idea all along, i tried to implement that thought, but with no success. What should be the steps? Shouls i create 2 functions for each side or..? Server starts, listens for incoming conections, recieves conection, starts a thread with that conection...
Ill post those ill functions a bit later.
Re: Client-Server programm creation
Server waits for a request.
Client sends request for a file
Server sends response: requested file or error message
Re: Client-Server programm creation
I just started networking and i am having a bit of a trouble understanding it all + the creepy deadline. getLocation is at the start of the run block for the server, fileRequest() is before the client.RecieveFile() call. Are these functions ok? Im getting a null :|
Made 2 functions:
Code :
public void fileRequest(String interestFile)
{
try
{
OutputStream serverIn=server.getOutputStream(); //here...
BufferedWriter sender=new BufferedWriter(new OutputStreamWriter(serverIn));
sender.write(interestFile);
sender.close();
}
catch(IOException io)
{
}
}
Code :
public void getLocation()
{
try
{
InputStream getName=newCon.getInputStream();
DataInputStream getterName=new DataInputStream(getName);
location=getterName.readUTF();
getterName.close();
}
catch(IOException io)
{
}
}
Code :
public void actionPerformed(ActionEvent e)
{
if(host.getText().equals("") || socket.getText().equals("") || file.getText().equals(""))
{
dialog=new ErrorMessage(" Something is missing! ","Excuse me, but..", null);
dialog.setVisible(true);
}
else
{
try
{
client.setHost(host.getText());
client.setPort(Integer.parseInt(socket.getText()));
client.setFile(file.getText());
client.fileRequest(client.interestFile);
client.RecieveFile();
}
catch(NumberFormatException eror)
{
dialog=new ErrorMessage("Do you know how to use this?","I have to ask..", null);
dialog.setVisible(true);
}
}
}
Code :
public void run()
{
try
{
getLocation();
System.out.println("Using port: "+newCon.getPort());
System.out.println("Adress: "+ newCon.getInetAddress().getHostAddress());
File file=new File(location);
byte [] bytearray=new byte[(int)file.length()];
FileInputStream fileInput = new FileInputStream(file);
BufferedInputStream bufferedIn=new BufferedInputStream(fileInput);
bufferedIn.read(bytearray,0,bytearray.length);
OutputStream out= newCon.getOutputStream();
out.write(bytearray,0,bytearray.length);
out.flush();
out.close();
bufferedIn.close();
newCon.close();
}
catch(IOException e)
{
System.out.println(e.getStackTrace());
}
}
Re: Client-Server programm creation
I wouldn't close the connection after sending the request. Wait until the response is received.
Put calls to the printStackTrace() method in all the catch blocks.
getLocation() should return a value.
Re: Client-Server programm creation
How to wait for a response? To wait for a response i should send one, no?
Re: Client-Server programm creation
Doing a read() would block/wait for a response.
Re: Client-Server programm creation
Well now, thats does not work. A bit more detail maybe? I bet you can clearly see, that i dont understand completely how these things work yet. Are you collecting posts or something?
Re: Client-Server programm creation
Quote:
thats does not work
Please explain what "does not work"?
Can you post the code that shows what you did and explain what happened when it was executed?
Quote:
Are you collecting posts or something?
Can you explain what that means?
Re: Client-Server programm creation
I already posted the changes, with those two functions, and where they were added. c
This happens:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at mess.MyClient.fileRequest(MyClient.java:23)
at mess.ClientFrame$1.actionPerformed(ClientFrame.jav a:77)
at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Re: Client-Server programm creation
Quote:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at mess.MyClient.fileRequest(MyClient.java:23)
The code at line 23 had a null variable when it was executed. Look at line 23 and find what variable was null and then backtrack in the code to see why that variable did not have a non-null value.