Send string to socket server from applet

Am trying to send a string to socket server from my applet:
Server:
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Server extends JApplet
ServerSocket srvr;
Socket skt;
PrintWriter out;
BufferedReader in;
Server()
String data = "server";
try
srvr = new ServerSocket(5555);
skt = srvr.accept();
out = new PrintWriter(skt.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(skt.getInputStream()));
while (in.ready())
System.out.println(in.readLine());
out.print(data);
out.close();
in.close();
skt.close();
srvr.close();
catch(Exception e)
System.out.print(e);
public static void main(String[] aslan)
new Server();
My applet where I have my client:
Socket skt;
BufferedReader in;
PrintWriter out;
try
skt = new Socket("localhost", 5555);
out = new PrintWriter(skt.getOutputStream(),true);
in = new BufferedReader(new InputStreamReader(skt.getInputStream()));
while (in.ready())
System.out.println(in.readLine());
in.close();
catch(Exception e)
System.out.print(e);
public void actionPerformed( ActionEvent e )
if(e.getSource() == button)
out.println("test");
But when the button is pushed the client is supposed to send the string "test" to the server but nothing happens can someone plz help me with this?

Am trying to send a string to socket server from my
applet:
Server:
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Server extends JApplet
ServerSocket srvr;
Socket skt;
PrintWriter out;
BufferedReader in;
Server()
String data = "server";
try
srvr = new ServerSocket(5555);
skt = srvr.accept();
out = new PrintWriter(skt.getOutputStream(), true);
in = new BufferedReader(new
InputStreamReader(skt.getInputStream()));
while (in.ready())
System.out.println(in.readLine());
out.print(data);
out.close();
in.close();
skt.close();
srvr.close();
catch(Exception e)
System.out.print(e);
public static void main(String[] aslan)
new Server();
My applet where I have my client:
Socket skt;
BufferedReader in;
PrintWriter out;
try
skt = new Socket("localhost", 5555);
out = new PrintWriter(skt.getOutputStream(),true);
in = new BufferedReader(new
InputStreamReader(skt.getInputStream()));
while (in.ready())
System.out.println(in.readLine());
in.close();
catch(Exception e)
System.out.print(e);
public void actionPerformed( ActionEvent e )
if(e.getSource() == button)
out.println("test");
But when the button is pushed the client is supposed
to send the string "test" to the server but nothing
happens can someone plz help me with this? Your server code while (in.ready()) is going to block indefinitely.
Remove the while loop and just write your ouput and close the connection on the server.

Similar Messages

  • Firewall: Error sending to the socket, server is not responding.

    Hi all,
    I'm trying to connect AIX machine to NT DB2 Database through JDBC with a firewall. I'm using the standard port 6789 in JDBC Applet Server in NT DB2. But I've gotten the following message:
    COM.ibm.db2.jdbc.DB2Exception: [IBM][JDBC Driver] CLI0614E Error sending to the socket, server is not responding. SQLSTATE=08S01
    The connection chain I'm using for AIX side is:
    jdbc:db2://192.168.3.4:6789/DATABASE
    I've configured the firewal to allow the port 6789 to be used, and also the other port 51544 (it's for remote administration, I think). I've also checked that wires and other stuff is working fine, but stil I cannot connect to the Database.
    I don't know if there's something missing on the firewall configuration. Before, everything was working without the firewall.
    Any help will be apreciated, THanks.
    Rodrigo, SPAIN

    It looks like no port problem is happening, because we freed all the ports just to see if client tried to use some of them without our knowing. But it was still the same.
    We were thinking about routing issues, but we were able to ping from client to server, and ports 6789 and 51544 were open as well. Maybe JDBC Client Driver is looking for an different IP address than 192.168.3.4. We know the firewall doesn't receive any query from JDBC Client, and that's very strange because if you see the routing tables in AIX machine, the default route is the firewall. Of course, there's not any other static defined route for the server (192.168.3.4), so it's supposed that default route is going to be used. But it's not.
    We also restarted client machine from scratch but nothing. Maybe this problem happens because there's something wrong in AIX networking settings.
    Rodrigo

  • Problems send string through Socket

    I'm writing a simple chat.
    The server-side, when receive a request from a client act in this way:
    1_ Choose a random port between 8000 and 8100
    2_ Verify if the port is alredy used (otherwise it randomize another port)
    3_ Create a dynamicServer instance that listen at the new randomized port
    4_ Communicate the port to the Client
    The program doesn't have any problem with the point 1, 2 and 3.
    But for some reason I can't explain, it doesn't communicate with the client.
    Can you explain me why? (I can't work it out by myself T_T)
    This is the code of the server-side:
    public class ProcessoServer extends Thread {
        private int cport, i = 0;
        public ServerSocket server;
        private Component SezionePrincipale;
        private PrintStream cPort;
        private int[] portUsed = new int[100];
        private ChPort choose;
        @Override
        public void run()
            try {
            while(true) {
                    server = new ServerSocket(7777);
                    Socket s1 = server.accept();
                    if(s1.getInetAddress().toString().equals("/127.0.0.1"))
                        server.close();
                        s1.close();
                        break;
                    else {
                        cport = 8000 + (int)(Math.random() * 100);
                        choose = new Chport(cport, portUsed);
                        while(choose.Check() == false)
                            cport = 8000 + (int)(Math.random() * 100);
                            choose = new Chport(cport, portUsed);
                        portUsed[i] = cport;
                        i++;
                        new DynamicServer(cport);
                        cPort = new PrintStream(s1.getOutputStream());
                        cPort.println(cport);
                        cPort.flush();
                        cPort.close();
                        s1.close();
            catch(IOException ex)
            //an error
        public void removePort(int port)
            for(int b = 0; b <= portUsed.length; b++) {
                if(port == portUsed) {
    portUsed[b] = -1;
    public void haltServer() throws UnknownHostException, IOException {
    Socket stop = new Socket("127.0.0.1", 7777);
    This is the code of the client-side.public Connection(InetAddress ip) throws IOException
    Socket s1 = new Socket(ip, 7777);
    BufferedReader port = new BufferedReader(new InputStreamReader(s1.getInputStream()));
    Integer newPort=Integer.parseInt(port.readLine());
    System.out.println("the new port is "+String.valueOf(portaNuova));
    s2 = new Socket(ip, newPort);
    port.close();
    s1.close();

    M3kka wrote:
    I'm doing this because I thought that every single conversation (I'm not exactly writing a chat, the program should be something more similar to an Instant Messager) needs a single SocketIt does not require new Server Sockets. Each Socket is unique while sharing the same server port.
    Am I wrong? Yep.
    As I indicated, this is a pretty common misconception. The uniqueness of each socket is made using several pieces of information, the host and port on one end and the host and port on the other end. One of these pieces of information must be unique. How this is handled is that the client is generally speaking assigned a random port by the client TCP implementation (aka the OS).
    At any rate you don't have to go through these gyrations, the sockets returned from ServerSocket.accept will all be unique. TCP already does that for you.
    If you haven't seen it yet be sure to check out [_The Java Networking Tutorial_|http://java.sun.com/docs/books/tutorial/networking/index.html]

  • Sending strings to a server..

    public class sendToServer implements ActionListener {
    public static void main(String args[]) {
    new sendToServer();
    public sendToServer() {
            JFrame mainFrame = new JFrame("Sending to server test..");
            mainFrame.setSize(new Dimension(300, 300);
            Container frameCon = mainFrame.getContentPane();
            JButton send = new JButton("Send");
            frameCon.add(send);
    public void actionPerformed(ActionEvent e) {
    JButton b = (JButton) e.getSource();
    if(b.getText().equals("Send")) {
    Socket socket = new Socket("localhost", 9412);
    OutputStream os = socket.getOutputStream();
    PrintWriter pw = new PrintWriter(os);
    pw.write("Yo");
    }Im trying to send a string to a server..any help?

    Read the "Custom Networking" tutorial:
    http://java.sun.com/docs/books/tutorial/

  • Sending different types of data from applet to servlet

    Hi,
    I am writing an applet that uploads a file to a servlet. I can send the file to the servlet just fine.
    Applet Side
    1. open a URLConnection
    2. open a DataOutputStream
    3. write the file to the DataOutputStream
    Servlet Side:
    1. open a ServletInputStream from the HttpServletRequest
    2. write the bytes to a file
    This is all fine.
    However, I need to upload the filename (a String) with the file. How do I do this? I can't send the filename over as a String from the applet using the same DataOutputStream. right? This would corrupt the file that i am sending as the servlet wouldn't know that the difference between the filename and the actual contents of the file.
    Is there some property I can set in the urlconnection that gets passed to the request variable? i.e. URLConnection.setProperty ("filename", foo.txt) and then on the servlet side do this: String filename = eq.getProperty ("filename")
    Thank you for the help

    If all the additional data you want to send to server are textual or numaric data about the file (which is in the body of the request)
    Use those information as additional http headers.
    And read those header information from the servlet request object at the server side
    ex:-
    URL u = new URL("your url");
    HttpURLConnection c = (HttpURLConnection)u.openConnection();
    c.addRequestProperty("x-application-file-name","name of the file");
    c.addRequestProperty("x-application-file-size","size of the file");
    //then open the stream and write the data to the request body
    //             At server side         //
    String name = request.getHeader("x-application-file-name");
    long size= Long.parseLong(request.getHeader("x-application-file-size"));

  • Writing to file on server from applet

    ok i know this issue has been dealt with on numerous occasions but i would like someone to explain me in details what would be the best way of doing it.
    I know that one way of doing it is having a servlet which would perform I/O and would communicate with the applet via a socket. What I don't understand is when and how does the servlet start running.
    It has to be running to be able to first accept a connection from the applet and then listen on the specified port.
    So how does the servlet start running so as to be able to communicate with the applet?
    Could you please make your answers as precise as possible.
    Thanks

    Servlets are run by servlet containesr. You must start container first (Tomcat, Jetty, Weblogic, Websphere, ...) and then it will handle running servlet. Usually it is a first http-request that instantiates servlet on-demand, but you may configure it to be instantiated at container startup. So, only you have to worry about is to put servlet on container server and it will take care of the rest.
    Simple writing to a server-side file is easier to do with PHP if you have linux/unix-based web server. Just installing a servlet container for it might be a bit overkill.

  • Opening Output Stream to a file on the server from Applet

    Hi,
    I am trying to write a little applet which parses a file found on the server , lets the user select some Strings then write the selected Strings to a different file on the server. I use the following code:
    String fileName = new String("LineUp");
    URL docBase = null;
    URLConnection conn = null;
    try {
    docBase = new URL(ApppletName.codeBase, fileName);
    } catch (java.net.MalformedURLException e) {
    System.out.println("Couldn't create image: "
    + "badly specified URL");
    try {
    conn = docBase.openConnection();
    } catch(IOException e) {System.out.println(e);}
    String playerString;
    try {
    conn.setAllowUserInteraction(true);
    conn.setDoOutput(true);
    conn.connect();
    PrintWriter out = new PrintWriter(
    conn.getOutputStream());
    etc..
    The problem I am having is that the getOutputStream routine for the connection object does nothing other than throw an exception (I've stepped through the code and that is all the routine actually does). The connection is actually made but no output stream can be created. I have looked at the Java Tutorial (as I am fairly new to Java) and found a spot where they tell you how to write to a file on the server, which is the example I have followed. Any suggestions? What am I missing?

    Yes, that's what I thought. It talks about writing to a URL, and you have interpreted "URL" as if it meant "file". A URL is a "Uniform Resource Locator", which is a string that identifies a "resource" on the server. Often that corresponds to a file on the server, but not always. It could be a page that is dynamically generated by a script on the server.
    Look again at that page and you will see these words: "At the other end, a cgi-bin script (usually) on the server receives the data, processes it, and then sends you a response, usually in the form of a new HTML page." What that means is, you can't just upload a file to a URL unless you have programmed the server to deal with that upload. That's part of the basic design of the HTTP protocol.
    So, unfortunately, you can't do what you want all that easily. You would have to provide some programming at the server to handle the file upload for you. In Java that means writing a servlet and getting the web server to have that servlet handle all requests to a particular URL. I suspect you don't want to get into that just yet. But if you do, any decent book on Java servlets should have an example of how to upload files like this.

  • Send APDU to the card from applet on the card

    Hi
    I would like to send an APDU command to the card, from an applet on the actual card, in the same way I do from a PC with a card reader.
    The applet would first have been triggered by an external application through a card reader.
    I have seen this done on a SIM card not based on JavaCard, but I wonder if the JavaCard API allows it.
    Thanks
    asciz

    APDU = Application Protocol Data Unit which means that this is the applicative protocol that allows a IFD to communicate with a smart card. This protocol resides on top of the TPDU (Transfer Protocol Data Unit) that defines how the data are sent to the card. I dun think that it's possible for an applet on the SIM to be able to send APDU command to another applet on the SIM without going through the smart card reader.
    To make 2 applets communicate on a java card there are other ways, like opening a door in your applet to let other applet to call a method from your applet.
    Thomas
    http://jaccal.sourceforge.net/

  • How to send string data through socket!

    Is there any method to send string data over socket.
    and if client send string data to server,
    How to get that data in server?
    Comments please!

    Thank for your kind answer, stoopidboi.
    I solved the ploblem. ^^;
    I open the source code ^^; wow~~~~~!
    It will useful to many people. I spend almost 3 days to solve this problem.
    The program works like this.
    Client side // string data ------------------------> Server side // saving file
    To
    < Server Side >
    * Server.java
    * Auther : [email protected]
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Server extends JFrame
         private JTextField enter;
         private JTextArea display;
         ObjectInputStream input;
         DataOutputStream output;
         FileOutputStream resultFile;
         DataInputStream inputd;
         public Server(){
              super("Server");
              Container c = getContentPane();
              enter = new JTextField();
              enter.setEnabled(false);
              enter.addActionListener(
                   new ActionListener(){
                        public void actionPerformed(ActionEvent ev){
                             //None
              c.add(enter, BorderLayout.NORTH);
              display = new JTextArea();
              c.add(new JScrollPane(display),
                     BorderLayout.CENTER);
              setSize(300, 150);
              show();
         public void runServer(){
              ServerSocket server;
              Socket connection;
              int counter = 1;
              display.setText("");
              try{
                   server = new ServerSocket(8800, 100);
                   while(true){
                        display.append("Waiting for connection\n");
                        connection = server.accept();
                        display.append( counter + " connection is ok.\n");
                        display.append("Connection " + counter +
                             "received from: " + connection.getInetAddress().getHostName());
                        resultFile = new FileOutputStream("hi.txt");
                        output = new DataOutputStream(resultFile);
                        output.flush();
                        inputd = new DataInputStream(
                             connection.getInputStream()
                        display.append("\nGod I/O stream, I/O is opened\n");
                        enter.setEnabled(true);
                        try{
                             while(true){
                                  output.write(inputd.readByte());
                        catch(NullPointerException e){
                             display.append("Null pointer Exception");
                        catch(IOException e){
                             display.append("\nIOException Occured!");
                        if(resultFile != null){
                             resultFile.flush();
                             resultFile.close();
                        display.append("\nUser Terminate connection");
                        enter.setEnabled(false);
                        resultFile.close();
                        inputd.close();
                        output.close();
                        connection.close();
                        ++counter;
              catch(EOFException eof){
                   System.out.println("Client Terminate Connection");
              catch(IOException io){
                   io.printStackTrace();
              display.append("File is created!");
         public static void main(String[] args){
              Server app = new Server();
              app.addWindowListener(
                   new WindowAdapter(){
                        public void windowClosing(WindowEvent e){
                             System.exit(0);
              app.runServer();
    < Client side >
    * Client.java
    * Auther : [email protected]
    package Client;
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Client extends JFrame
         private JTextField enter;
         private JTextArea display;
         DataOutputStream output;
         String message = "";
         public Client(){
              super("Client");
              Container c = getContentPane();
              enter = new JTextField();
              enter.setEnabled(false);
              enter.addActionListener(
                   new ActionListener(){
                        public void actionPerformed(ActionEvent e){
                             //None
              c.add(enter, BorderLayout.NORTH);
              display = new JTextArea();
              c.add(new JScrollPane(display), BorderLayout.CENTER);
              message = message + "TT0102LO12312OB23423PO2323123423423423423" +
                        "MO234234LS2423346234LM2342341234ME23423423RQ12313123213" +
                        "SR234234234234IU234234234234OR12312312WQ123123123XD1231232" +
                   "Addednewlinehere\nwowowowwoww";
              setSize(300, 150);
              show();
         public void runClient(){
              Socket client;
              try{
                   display.setText("Attemption Connection...\n");
                   client = new Socket(InetAddress.getByName("127.0.0.1"), 8800);
                   display.append("Connected to : = " +
                          client.getInetAddress().getHostName());
                   output = new DataOutputStream(
                        client.getOutputStream()
                   output.flush();
                   display.append("\nGot I/O Stream, Stream is opened!\n");
                   enter.setEnabled(true);
                   try{
                        output.writeBytes(message);
                   catch(IOException ev){
                        display.append("\nIOException occured!\n");
                   if(output != null) output.flush();
                   display.append("Closing connection.\n");
                   output.close();
                   client.close();
              catch(IOException ioe){
                   ioe.printStackTrace();
         public static void main(String[] args){
              Client app = new Client();
              app.addWindowListener(
                   new WindowAdapter(){
                        public void windowClosing(WindowEvent e){
                             System.exit(0);
              app.runClient();

  • Send String failed using socket

    Hi all,
    I have just finished a program which send a string client to the host server using simple socket. The program is developed using JBuilder9 and run well in winxp pro. When the same program run in linux (red hat), the host server can only see the connection and close. The string never receive in the server side. The problem is worked out like the following
    -create socket
    -create output stream using "PrintWriter"
    -send string
    -close socket
    Pls. comment on what I should do to debug this problem.
    Thanks,
    Peter

    Hi all,
    Thanks for your assistance. I have log down the following from linux using "tcpdump"
    13:16:48.218624 128.128.2.161.33083 > pmon-srv0.999: P 1:42(41) ack 1 win 5840 <nop,nop,timestamp 158365 0> (DF)
    13:16:48.219105 128.128.2.161.33083 > pmon-srv0.999: F 42:42(0) ack 1 win 5840 <nop,nop,timestamp 158365 0> (DF)
    13:16:48.219742 pmon-srv0.999 > 128.128.2.161.33083: . ack 43 win 64199 <nop,nop,timestamp 2471694 158365> (DF)
    13:16:48.219876 pmon-srv0.999 > 128.128.2.161.33083: F 1:1(0) ack 43 win 64199 <nop,nop,timestamp 2471694 158365> (DF)
    13:16:48.219894 128.128.2.161.33083 > pmon-srv0.999: . ack 2 win 5840 <nop,nop,timestamp 158365 2471694> (DF)
    13:17:59.746088 128.128.2.211.1633 > pmon-srv0.999: P 1:43(42) ack 1 win 17520 (DF)
    13:17:59.756047 128.128.2.211.1633 > pmon-srv0.999: F 43:43(0) ack 1 win 17520 (DF)
    13:17:59.756493 pmon-srv0.999 > 128.128.2.211.1633: . ack 44 win 64198 (DF)
    13:17:59.756989 pmon-srv0.999 > 128.128.2.211.1633: F 1:1(0) ack 44 win 64198 (DF)
    13:17:59.757103 128.128.2.211.1633 > pmon-srv0.999: . ack 2 win 17520 (DF)
    128.128.2.211 is the client in winxp pro
    128.128.2.161 is the client in linux
    pmon-srv is the server
    In the first line of each section, it shows that number of bytes have push to the server. I don't know what should I do next to solve the problem.
    Here is the source code
    public class pconnect {
    String ip_addr;
    String fromServer, toServer;
    int i,port;
    Socket pmSocket;
    BufferedReader pm_in;
    PrintWriter pm_out;
    public pconnect(String ip, int portno) {
    ip_addr=ip;
    port=portno;
    try {
    pmSocket = new Socket(ip_addr, port);
    pm_out = new PrintWriter( pmSocket.getOutputStream(), true );
    pm_in = new BufferedReader( new InputStreamReader( pmSocket.getInputStream() ) );
    } catch (Exception err) {
    System.err.println(err);
    System.exit(0);
    public void sendMsg(String msg) {
    try {
    Thread.sleep(5000);
    } catch (InterruptedException e){}
    if (pmSocket.isConnected()) {
    try {
    System.out.println("Stream Status: " + pmSocket.isOutputShutdown());
    System.out.println("Bound Status: " + pmSocket.isBound());
    pm_out.println(msg);
    if (pm_out.checkError()) {
    System.out.println("Socket error");
    }catch (Exception e){System.out.println("Exception: " + e);}
    try {
    pmSocket.close();
    } catch (Exception err) {
    System.err.println("Closed Error: "+err);
    public static void main(String[] args) {
    System.out.println(args.length);
    System.out.println(args[0]);
    pconnect pconnect1 = new pconnect(args[0],Integer.parseInt(args[1]));
    pconnect1.sendMsg("SET00000000N|ALARM:MBX TEST|c29K1920755D");
    Thanks,
    Peter

  • How to send XML packet from external socket server to OSB

    Hi folks,
    How do I use external Socket Server(tcp) to send payload to OSB ?
    I have configured the socket protocol in my OSB. I am also able to send and receive responses by testing my proxy services from OSB itself.
    But now, we want to use some external socket (tcp)server to be able to fire some xml file and then receive response on OSB.
    Please help
    salil

    You need to use a socket client application to send a message to a socket where your proxy is listening. For receiving a message at a socket, configure business service at OSB.
    Regards,
    Anuj

  • Newbee help: applet sends itself to sock server!!!

    hi all,
    im a c# developer 'n new to java applets,
    my client have a server and a web java applet that connects to server using socket
    i've got a task to create a c# windows application to do same as the applet.
    im just confused, when i saw the applet code, it connects to server, and sends itself to the server!!!
    here's the code, can anyone plz help me what's actually happening...
                   try
                        to_server = new Socket(getCodeBase().getHost(), port_of_server);
                        _OOS = new ObjectOutputStream(to_server.getOutputStream());
                        is = new DataInputStream(new BufferedInputStream(to_server.getInputStream()));
                        os = new PrintStream(new BufferedOutputStream(to_server.getOutputStream(), 1024), false);
                        txtAreaMessages.setText("");
                        txtMessage.setEnabled(true);
                        txtMessage.setText("");
                    catch(Exception exception)
                        _logout();
                        txtAreaMessages.appendText("Could not Connect...");
                        return;
                    // THIS IS THE CODE WHERE IM CONFUSED!!!
                    _OOS.writeObject(this);
                    _OOS.flush();
                    os.print(1);
                    os.flush();
                    ClientNew clientnew = new ClientNew(is, os, txtAreaMessages);
                    clientnew.start();
                    btnLogin.setEnabled(false);
                    txtLoginName.setEnabled(false);
                    btnSend.setEnabled(true);
                    btnMobMessage.setEnabled(true);
                    ch_thread = new Thread(this, "abc");
                    ch_thread.start();alll is well, but what's with ObjectOutputStream, and why its sending (this) to server??
    im asking this question here because i wanna learn it as well :D
    it'll be really great help if someone can tell me same to do in c#
    // chall3ng3r //

    the decompiled source code should tell you what you need to rewrite the client-server communications, which you will unfortunately have to do.
    is it some kind of trick to allow only connection from the applet not from c# or vb??no, its an easy, java-specific method of communication.
    if it is, how to do same in c#, (just gimme a hint, not the full solution)yes, you would have to do work to allow any other language to emulate this.
    no, its not impossible to do.
    i know nothing about c#

  • Problem in sending image from applet to servlet

    dear friends,
    i have a need to send an image from applet to servlet via HttpConnection and getting back that image from applet.
    i am struggling with this sice many hours and got tired by searching any post that would help me but haven't got yet.
    i tried using this code but it dosent make any execution sit right. i got NPE at ImageIcon.getDescription() line;
    at applet side
          jf.setContentPane(getJContentPane());
                     FileDialog fd=new FileDialog(jf,"hi");
                     fd.setMode(FileDialog.LOAD);
                     fd.setVisible(true);   
                     v=new Vector();
                     try{                                                
                               FileInputStream fis=new FileInputStream(new File(fd.getDirectory()+fd.getFile()));      
                               byte[] imgbuffer=new byte[fis.available()];
                               fis.read(imgbuffer);
                               ImageIcon imgdata=new ImageIcon(imgbuffer);
                               v.add(0,imgicon);
                                String strwp ="/UASProject/Storeimage";              
                                URL servletURL = new URL(getCodeBase(),strwp);             
                                HttpURLConnection servletCon = (HttpURLConnection)servletURL.openConnection();       
                                servletCon.setDoInput(true); 
                                servletCon.setDoOutput(true);
                                servletCon.setUseCaches(false);
                                servletCon.setDefaultUseCaches(false);   
                                servletCon.setRequestMethod("POST");     
                                servletCon.setRequestProperty("Content-Type", "application/octet-stream");   
                                servletCon.connect();            
                                ObjectOutputStream oboutStream = new ObjectOutputStream(servletCon.getOutputStream());                     
                                oboutStream.writeObject(v);
                                v.remove(0);
                                oboutStream.flush();      
                                oboutStream.close();  
                                //read back from servlet
                                ObjectInputStream inputStream = new ObjectInputStream(servletCon.getInputStream());
                                 v= (Vector)inputStream.readObject();                     
                                 imgicon=(ImageIcon)v.get(1);
                                 showimg.setIcon(imgicon);
                                 this.getContentPane().validate();
                                 this.validate();  
                                inputStream.close();                                                        
                             //  repaint();
                     }catch(Exception e){e.printStackTrace();}  and this is at servlet side
            try {       
                         Vector v=new Vector();                    
                         ObjectInputStream inputFromjsp = new ObjectInputStream(request.getInputStream());                                      
                          v = (Vector)inputFromjsp.readObject();                                                                                                          
                          imgicon=(ImageIcon)v.get(0);                     
                          inputFromjsp.close();            
                          System.out.println(imgicon.getDescription());                                      
                          v.remove(0);
                          v.add(1,imgicon);
    //sending back to applet
                           response.setContentType("application/octet-stream");
                          ObjectOutputStream oboutstream=new ObjectOutputStream(response.getOutputStream());            
                          oboutstream.writeObject(v);
                          oboutstream.flush();
                          oboutstream.close();
                   } catch (Exception e) {e.printStackTrace();}  i really need your help. please let me out of this headche
    thanks
    Edited by: san_4u on Nov 24, 2007 1:00 PM

    BalusC wrote:
    san_4u wrote:
    how can i made a HttpClient PostMethod using java applets? as i have experience making request using HttpURLConnection.POST method. ok first of all i am going make a search of this only after i will tell. please be onlineOnce again, see link [3] in my first reply of your former topic.
    yeah! i got the related topic at http://www.theserverside.com/tt/articles/article.tss?l=HttpClient_FileUpload. please look it, i am reading it right now and expecting to be reliable for me.
    well what i got, when request made by html code(stated above) then all the form fields and file data mixed as binary data and available in HttpServletRequest.getinputstream. and at servlet side we have to use a mutipart parser of DiskFileItemFactory class that automatically parse the file data and return a FileItem object cotaing the actual file data,right?.You can also setup the MultipartFilter in your environment and don't >care about it further. Uploaded files will be available as request attributes in the servlet.is the multipartfilter class file available in jar files(that u suggested to add in yours article) so that i can use it directly? one more thing the import org.apache.commons.httpclient package is not available in these jar files, so where can got it from?
    one mere question..
    i looked somewhere that when we request for a file from webserver using web browser then there is a server that process our request and after retrieving that file from database it sends back as response.
    now i confused that, wheather these webservers are like apache tomcat, IBM's webspher etc those processes these request or there is a unique server that always turned on and process all the request?
    because, suppose in an orgnisation made it's website using its own server then, in fact, all the time it will not turned on its server or yes it will? and a user can make a search for kind of information about this orgnisation at any time.
    hopes, you will have understand my quary, then please let me know the actual process
    thanks
    Edited by: san_4u on Nov 25, 2007 11:25 AM

  • Communicating with server from an Applet.

    Hi, i've written a tetris game in an applet.
    But i want some way of saving the high scores of everyone on the server.
    Is they anyway to communicate the final score back to the server from the applet?
    I tried saving the scores to a text file but apparently the file would appear on the client.

    Here is some code that you may find useful. This works for the more flexible serialized object approach. For a query string, you would simply do a post on the servlet with the appropriate URL that includes the query string. However, I have found the following serialized object approach to be more convenient.
    import java.net.*;
    import java.io.*;
    This function sends an "AppletRequest" object to the servlet and gets the response back from the servlet in the form of a "ServletResponse" object.
    protected static ServletResponse talkToServlet(AppletRequest aReq) {
    ServletResponse sr = new ServletResponse();
    try {
    // Replace the following URL by the URL of your servlet
    servletURL = new URL("http://myservleturl/");
    servletConn = servletURL.openConnection();
    servletConn.setUseCaches (false);
    servletConn.setRequestProperty("Content-Type",
    "application/octet-stream");
    servletConn.setDoInput(true);
    servletConn.setDoOutput(true);
    } catch (MalformedURLException ex) {
    System.out.println("MalformedURLException"+ex.getMessage());
    } catch (IOException ex) {
    System.out.println("IOException"+ex.getMessage());
    } catch (Exception ex) {
    System.out.println ("GeneralException: " + ex.getMessage());
    try {
    outputToServlet = new ObjectOutputStream(servletConn.getOutputStream());
    outputToServlet.writeObject(aReq);
    outputToServlet.flush();
    outputToServlet.close();
    } catch (Exception ex) {
    System.out.println("GeneralException1: "+ex.getMessage());
    try {
    try{
    inputFrServlet = new ObjectInputStream(servletConn.getInputStream());
    sr = (ServletResponse) inputFrServlet.readObject();
    inputFrServlet.close();
    } catch (EOFException ex) {
    System.out.println("EOFException: "+ex.getMessage());
    } catch (IOException e) {
    System.out.println("IOException: "+e.getMessage());
    e.printStackTrace();
    } catch (ClassNotFoundException e) {
    System.out.println("ClassNotFoundException: "+e.getMessage());
    } catch (Exception e) {
    System.out.println("GeneralException2: "+e.getMessage());
    return(sr);

  • Send a string to a server

    Hi,
    I am going to write a java application that sends a string so a server. I don�t know what is on the server side(someone else has written the server part) just that my program is going to use sockets and what port number and IP the server has. I first start using datagrampackets but then I have to use byte array that would not work if the server just want a string ?? What should I use?
    /Thanks in advance

    Hi,
    your question is not clear... you can convert the byte array to a string by calling toString method on the byte array.. since the server port and IP is known, try amking a socket and send a string and see what happens by opening a socket inputstream.. read from the stream to understand what the server does..
    - Bibin.

Maybe you are looking for

  • Reset Safari -- Now I Can No Longer Access Secure Sites Or iTunes Store.

    Hi, A few days ago I reset Safari (I'm still not sure why... boredom??). Well, now I'm paying for it. Now I can't access secure sites (such as gmail, bank accounts, etc.). in Safari. When trying to access a secure site I get an error window that read

  • Shopping cart error while creation

    Hello. In PPOMA_BBP, i  moved a user from an organisational unit to another one manually. 2) while creating a shopping cart with this user, i get the following errors:    i) No data found for partner '000000134', inform system admin    ii) No address

  • Is anyone experiencing an issue with iOS 8.0.2 where you don't receive photos sent from someone on iOS 7.1.2?

    I'm using an iPhone 6 on iOS 8.0.2.  My brother is using an iPhone 5S on iOS 7.1.2. He just tried to send me some photos with iMessage & they didn't make it to my iPhone 6. However, they did make it thru to my iPad, which is still on 7.1.2. I just tr

  • BDC Session ID from RFBIBL01

    Hi Experts, I have created a program to post the benefits and the claims in FI using the standard posting program RFBIBL01. The data comes from a file and accordingly gets formatted and the gets posted using the mentioned program. My requirement is t

  • 881W Integrated AP

    I am having an issue with an 881W router with the integrated AP. Our campus is using 1310 bridges to connect a remote apartment that houses students. Within that apartment we have a 881W router and are using the integrated AP. We have the advancedips