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/

Similar Messages

  • 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.

  • 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();

  • HTTPService problems while sending a String Variable to Server

    I have an xml in string form..... I want to send it as an http request to the server, which is written in .NET... server wud make its decession on the basis of this xml and wud return me another xml as http response..
    Problem ---->
    this request reaches server but when i look at the request reached at server it has my client infotmation but does not has my variable anywhere...... i iterate through all the parameters in Request.Params... but I don't find my string at all.... any idea why I can't find my sent variable ???
    Actionscript code to send xmlString to .NET Server using HTTPService:
    public function sendRequest(syncXmlString : String, httpResultHandler : Function) : void {
    try {
       var objectParam : Object = {name:PARAM_NAME, value:syncXmlString };
       var params : Object = [objectParam];
       var httpService : HTTPService = new HTTPService();
       httpService.url = serverUrl;
       httpService.method = HTTPRequestMessage.POST_METHOD;
       httpService.contentType =  HTTPService.CONTENT_TYPE_XML;
       httpService.resultFormat = HTTPService.RESULT_FORMAT_XML;
       httpService.addEventListener(ResultEvent.RESULT, httpResultHandler);
       httpService.addEventListener(FaultEvent.FAULT, httpFaultHandler);
       httpService.send(params);
    } catch (err : Error) {
       Alert.show(err.message);
    Thanks and Regards,
    Ahmed.

    No, that is the problem, the request object should not be an indexed array[], it should be an Object{}.  Remove that imtermediate array and pass objectParams in the send()
    Also, don't mess with the contentType without very good reason.
       httpService.contentType =  HTTPService.CONTENT_TYPE_XML;
    that says you are sending XML, but you are not, you are sending the default name=value pairs.  Remove that assignment and leave it at the default "form"
    One more, you do not want that resultFormat, it is the legacy AS2 class.  You want E4X
       httpService.resultFormat = RESULT_FORMAT_E4X;
    Tracy

  • 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.

  • If object is send twice BUT CHANGED server doesn't respond properly

    It seams there is a bug in Java 6 Serialization:
    Instantiate object x.
    Send it to the server and check the values.
    Change your client-side instance.
    Resend and check the values again.
    The server still shows the old values.
    To prove this is wrote a little code example:
    package testserializablebug;
    import java.io.Serializable;
    public class SharedObject implements Serializable {
        private String s;
        private int i;
        public SharedObject(String s, int i) {
            this.s = s;
            this.i = i;
        public void setI(int i) {
            this.i = i;
        @Override
        public String toString() {
            return s + "::" + i;
    package testserializablebug;
    import java.io.*;
    import java.net.*;
    public class ClientTest {
        DataInputStream in;
        ObjectOutputStream outO;
        public ClientTest() throws UnknownHostException, IOException {
            Socket socket = new Socket("localhost", 8000);
            in = new DataInputStream(socket.getInputStream());
            outO = new ObjectOutputStream(socket.getOutputStream());
            SharedObject so = new SharedObject("Text", 3);
            compareResponse(so);
            so.setI(5);
            compareResponse(so);
        private void compareResponse(SharedObject so) throws IOException {
            outO.writeObject(so);
            String actual = in.readUTF();
            String expected = so.toString();
            if (!actual.equals(expected)) {
                System.err.println("actual    " + actual);
                System.err.println("expected  " + expected);
            } else {
                System.out.println("OK        " + actual);
        public static void main(String[] args) throws UnknownHostException, IOException {
            new ClientTest();
    package testserializablebug;
    import java.io.*;
    import java.net.*;
    public class ServerTest {
        public static void main(String[] args) throws IOException, ClassNotFoundException {
            Socket socket = new ServerSocket(8000).accept();
            ObjectInputStream inO = new ObjectInputStream(socket.getInputStream());
            DataOutputStream out = new DataOutputStream(socket.getOutputStream());
            SharedObject so1 = (SharedObject) inO.readObject();
            out.writeUTF(so1.toString());
            SharedObject so2 = (SharedObject) inO.readObject();
            out.writeUTF(so2.toString());
    }Is this a bug, or am doing something wrong? Any ideas how i can bypass this bug (if it is)?

    Is this a bug, or am doing something wrong? Any ideas how i can bypass this bug (if it is)?It isn't a bug. Read the javadoc for ObjectOutputStream, and for the reset method.
    Kaj

  • Not Sure How To Send String

    I'm totally new to trying to network using Java and extremely poor at networking in general so bear with me here.
    I'm trying to make a top down shooter and currently the application allows the user to either play as host or connect to a host but all the network communication handling I'm doing involves creating strings, sending them along the connection and interpreting the strings on their reciept.
    The problem I'm having is I keep getting an unexpected end of file exception when it tries to read in the string.
    I used a basic IM application as an example of how to connect and send info in Java, which is where I got the idea to use in.readUTF and out.writeUTF to send string information but upon looking into this problem it seems to me that read/writeUTF is not really designed for strings and there should be something else I should use instead but I'm not sure what?
    Also I'm using this to communicate point information of each player and as I understand it I should be using TCP to do this as that was what the example I'm using said it used. Though I think it might be more useful to use UDP as it's faster and it shouldn't matter if I drop a packet or two, though I'm not sure where in my code it specifies a difference between the two and if that really is the best idea.
    Here's a zip of my netbeans project, though be warned it's VERY messy, probably the messiest code I've ever written, not to mention hacky as well: http://rapidshare.com/files/369943023/KerazehDood.zip
    Any help would be great.
    Thanks.
    Edited by: ThePermster on Mar 30, 2010 6:59 AM

    Thanks that seems to make much more sense, still having some troubles though.
    Ok so now the majority of it seems to be working and it seems to be sending the String just fine. And I'm having it send the String to the BufferedWriter "out" and then using the newLine() method to send a carriage return but the BufferedReader on "in" seems to not detect the carriage return.
    I have it doing a readLine() so that (as I understand it) it should be blocking, waiting until an end of line character so I assume each call of newLine() should have it pick up something but a quick breakpoint shows that it never stops blocking on readLine().
    I assume the connection is fine because the application running as server uses the socket object returned by the accept() method.
    Is there something I've perhaps misunderstood about the BufferedReader's readLine() method?
    Here's the new version of my netbeans project:
    http://rapidshare.com/files/371224512/KerazehDood.rar
    Also on a different line of questioning, I'm just wondering about socket convention.
    I was thinking it'd be useful in a game similar to what I'm attempting to make to not only send player position information but also client keypress information, I was just wondering, if you're doing something like that would it be frowned upon to use two separate ports? I think it would make the implementation far more legible and easy to structure but wasn't sure if applications usually try to stick to only one port or not.
    Thanks.
    Edited by: ThePermster on Apr 2, 2010 10:54 AM

  • Getting exception when trying to send data to a server

    Hi all,
    I am working on to connect to a remote machine sendng data to remote machine and testing whether data is reaching to machine or not..but when i do it i get the following exception
    java.io.EOFException
    at java.io.DataInputStream.readUnsignedShort(Unknown Source)
    at java.io.DataInputStream.readUTF(Unknown Source)
    at java.io.DataInputStream.readUTF(Unknown Source)
    at Client.main(Client.java:37)
    and this is my code
    import java.net.*;
    import java.io.*;
    public class Client {
    public static void main(String[] args) {
    int serverPort = 8080; // make sure you give the port number on which the server is listening. 
    String address = "remotehost"; // this is the IP address of the server  computer.
      try { 
    Socket socket = new Socket(address, serverPort); // create a socket with the server's IP address and server's port. 
    System.out.println("Yes! I just got hold of the program.");
    // Get the input and output streams of the socket, so that you can receive and send data to the client. 
    InputStream sin = socket.getInputStream(); 
    OutputStream sout = socket.getOutputStream();
    // Just converting them to different streams, so that string handling becomes easier.
    DataInputStream in = new DataInputStream(sin);
    DataOutputStream out = new DataOutputStream(sout);
    // Create a stream to read from the keyboard. 
    BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
    String line = null; 
    System.out.println("Type in something and press enter. Will send it to the server and tell ya what it thinks."); 
    System.out.println();
    while(true) {
    line = keyboard.readLine(); // wait for the user to type in something and press enter.
    System.out.println("Sending this line to the server...");
    out.writeUTF(line); // send the above line to the server.
    out.flush(); // flush the stream to ensure that the data reaches the other end. 
    line = in.readUTF(); // wait for the server to send a line of text.
    System.out.println(" : " + line);
    System.out.println(); 
      } catch(IOException e) if any knows what's the problem please help me..
    Thanks

    We'll need a little more info. If you're doing anything like the following then there's a problem:
    File f = new File("demo.txt");
    The problem is that the demo.txt file is not in the current directory - it's in the rmi\compute directory.
    This should work but it's not recommended:
    File f = new File("c:\\rmi\\compute\\demo.txt");
    You should substitue File.separator for the "\\" chars.

  • Sending XML messages from server to client using POST method

    Dear everyone,
    I have a simple client server system - using Socket
    class on the server side and URLConnection class on
    the client side. The client sends requests to the
    server in the form of an XML message using POST method.
    The server processes the request and responds with
    another XML message through the same connection.
    That's the basic idea.
    I have a few questions about headers and formats
    especially with respect to POST.
    1. In what format should the response messages from the
    server be, for the client? Does the server need to
    send the HTTP headers - for the POST type requests?
    Is this correct?:
       out.println("HTTP/1.1 200 My Server\r");
       out.println("Content-type: text/xml\r");
       out.println("Content-length: 1024\r");
       out.println("\r");
       out.println("My XML response goes here...");2. How do I read these headers and the actual message
    in the client side? I figured my actual message was
    immediately after the blank line. So I wrote
    something like this:
       String inMsg;
       // loop until the blank line is through.
       while (!"".equals(inMsg = reader.readLine()))
          System.out.println(inMsg);
       // get the actual message and process it.
       inMsg = reader.readLine();
       processMessage(inMsg);But the above did not work for me. Because I seem to
    be receiving a blank line after each header! (I suppose
    that was because of the "\r".) So what should I do?
    3. What are the different headers I must pass from
    server to the client to safeguard against every
    possible problem?
    4. What are the different exceptions I must be prepared
    for this situation? How could I cope with them? For
    example, time outs, IOExceptions, etc.
    Thanks a lot! I appreciate all your help!
    George

    hello,
    1) if you want to develop a distributed application with XML messages, you can look in SOAP.
    it's a solution to communicate objects distributed java (or COM or other) and it constructs XML flux to communicate between them.
    2) if it can help you, I have developed a chat in TCP/IP and, to my mind, when you send datas it's only text, so the format isn't important, the important is your traitement behind.
    examples :
    a client method to send a message to the server :
    public void send(String message)
    fluxOut.println(message);
    fluxOut.flush();
    whith
    connexionCourante = new Socket(lAdresServeur, noPort);
    fluxOut= new PrintWriter( new OutputStreamWriter(connexionCourante.getOutputStream()) );
    a server method in a thread to receive and print the message :
    while(true)
    if (laThread == null)
    break;
    texte = fluxIn.readLine();
    System.out.println(texte);
    that's all ! :)
    If you want to use it for your XML communication, it could be a good idea to use a special message, for example "@end", to finish the server
    ex :
    while(true)
    if (laThread == null)
    break;
    texte = fluxIn.readLine();
    // to stop
    if (texte.equals("@end"))
    {break;}
    processMessage(texte );
    hope it will help you
    David

  • Classcast exception while sending objects to the server

    I'm getting classcast exception when i try to send objects from the java webstart application at the client side to a server. Its working fine if I do the same without using javaweb start. I'm using hessian client to send objects to the server.
    I've a web app that gets outlook contacts from the client machine and send those to the server. I'm sending these contacts as custom objects(OutlookContact) to the server using hessian client. But these objects are being sent to the server as String objects but not as OutlookContact objects. I don't know whats happening. Can anyone please tell me is there any setting that I need to set in the jnlp file.
    thanks,
    Jayaram

    I am also getting the same error. Please anybody can help

  • Can I close the connection after sending immediately on the server?

    I have a C/S program. On the server side, the process as following:
    1. accept (blocking)
    2. //a connection is established
    using a new socket to receive request data from client
    3. business processing ... (maybe several seconds)
    4. send response data to client
    5. close socket immediately
    6. listening continuely again
    The server side is running on linux and writed by Java, and client is running on windows and writed by C++ Builder.
    My problem is:
    1. if the server is running on windows, everything is OK.
    2. if the server is running on linux (that is exprcted), the client can not receive the response data from server, the client program said the connection is unavailable when he read from socket blockingly.
    3. if I add some delay, e.g. 500ms, between sending response and close the connection, the client can receive response normally.
    why above?
    thanks for help.
    Jack

    Sorry, long time to go away.
    package test.server;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.net.ServerSocket;
    import java.net.Socket;
    public class EchoServer {
         private int port; // listened port
         private ServerSocket ssock; // the server's ip
         public EchoServer(String host, int port) {
              this.port = port;
              // Create a ServerSocket
              try {
                   ssock = new ServerSocket(port);
                   SocketAddress addr = new InetSocketAddress(host, port);
                   ssock.bind(addr);
              } catch (Exception ex) {
                   ex.printStackTrace();
              new HandleThread().start();
         public class HandleThread extends Thread {
              public int ntohl(byte[] bytes, int offset) {
                   int length1 = ((((int) bytes[offset + 0]) << 24) & 0xff000000);
                   int length2 = ((((int) bytes[offset + 1]) << 16) & 0x00ff0000);
                   int length3 = ((((int) bytes[offset + 2]) << 8) & 0x0000ff00);
                   int length4 = ((((int) bytes[offset + 3]) << 0) & 0x000000ff);
                   return length1 + length2 + length3 + length4;
              public void run() {
                   InputStream in = null;
                   OutputStream out = null;
                   try {
                        while (true) {
                             System.out.println("Start Listening...  [" + port + "]");
                             Socket clisock = ssock.accept();
                             //clisock.setSoLinger(true, 1);
                             System.out.println( "SOLinger:" + clisock.getSoLinger());
                             try {
                                  System.out.println("Accepted Client Socket...  [" + clisock + "]");
                                  in = clisock.getInputStream();
                                  out = clisock.getOutputStream();
                                  // receive four bytes length
                                  byte[] lenbuff = new byte[4];
                                  in.read(lenbuff, 0, 4);
                                  int len = ntohl(lenbuff, 0);
                                  byte[] buff = new byte[len];
                                  in.read(buff, 0, len);
                                  System.out.println("Received length&#65306;" + len + "  " + new String(buff));
                                  Thread.sleep(1000);
                                  out.write(lenbuff);
                                  out.write(buff);
                                  out.flush();
                                  //Thread.sleep(500);
                                  System.out.println("Send finished&#12290;");
                             } catch (Exception ex) {
                                  ex.printStackTrace();
                             } finally {
                                  if (in != null) {
                                       try {
                                            in.close();
                                       } catch (Exception ex) {
                                  if (out != null) {
                                       try {
                                            out.close();
                                       } catch (Exception ex) {
                                  if (clisock != null) {
                                       try {
                                            long time00 = System.currentTimeMillis();
                                            clisock.close();
                                            System.out.println( "close socket&#65306;[" + (System.currentTimeMillis() - time00) + "]");
                                       } catch (Exception ex) {
                   } catch (Exception ex) {
                        ex.printStackTrace();
         public static void main(String[] args) throws Exception {
              if( args.length == 2 ) {
                   new EchoServer(args[0], Integer.parseInt(args[1]));
              } else if( args.length == 2 ) {
                   new EchoServer("127.0.0.1", Integer.parseInt(args[0]));
              } else {
                   new EchoServer("127.0.0.1", 16000);
    }In my application, the package is following:
    length(4bytes) + data
    I have a simple WinSocket Client, send data to this server and receive the response,the sending is OK, Server can receive all messages.But when client is ready to receive data, the winsock call return WSAECONNRESET(10054).
    If I uncomment "Thread.sleep(500);", it means wait some time before close socket, the client can receive all response data.
    why?

  • SMICM error while sending mail using SMTP server

    Hi All,
    We are not able send mails using SMTP server.
    We have made every settings necessary in SCOT, SO16 , SMTP service is activated, default domain is maintained etc
    Only things which seems to be wrong is in SMICM trace file.
    [Thr 13] *** ERROR => NiBufIConnect: non-buffered connect pending after 5000ms (hdl 29;10.26.24.44:1090) [nibuf.cpp    4608]
    [Thr 13] *** WARNING => Connection request from (0/1/0) to host: 10.26.24.44, service: 1090 failed (NIECONN_REFUSED)
    [icxxconn_mt.c 2321]
    This error is getting repeated in it.
    BUt I am not sure why it it trying to hit 10.26.24.44, as we dont have any server by this ip. The ip is only not resolvable from the server.
    1 more thing, at OS level, following parameter is maintained in profile :
    icm/server_port_1 = PROT=SMTP,PORT=25000,TIMEOUT=180
    But in SCOT, under SMTP node PORT is given as 25.
    Kindly let me know what going wrong here?
    Thanks

    also getting error as follows
    Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1
    Authentication Required. Learn more at
       at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
       at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from)
       at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
       at System.Net.Mail.SmtpClient.Send(MailMessage message)
       at ST_c121e07caaa94c21bb1355d4f753112f.vbproj.ScriptMain.Main()
       --- End of inner exception stack trace ---
       at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
       at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
       at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture)
       at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()

  • 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

  • When client send file  connection with server close

    please help me.
    i want to transfer a file via server - client model.
    Client send the file, server receive it.
    Then when i send a msg from server to client i have this error:
    java.net.SocketException: socket closed
    why the socket closed?

    client waiting for response. i don't know what to do.
    the client code is:
    import java.net.*;
    import java.io.*;                              
    class Client{               
         Socket clientSocket;               
           byte[] byteArray;                    
           BufferedInputStream bis;          
            BufferedOutputStream bos;          
           int in;                                   
           BufferedReader inm = null;
            PrintWriter outm = null;
           public Client(){
             try{
                    clientSocket = new Socket("localhost", 9632);
                   System.out.println("i am client & connect");
                   inm = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
                   outm = new PrintWriter(clientSocket.getOutputStream(), true);
                   System.out.println("------1--------" +clientSocket.isClosed());
                      outm.println("msg 1: hi");
                      System.out.println("from server__ " +inm.readLine());
                      outm.println("msg 2: now i will send you a file");
                      System.out.println("from server__ " +inm.readLine());
                      sendFile();
                     System.out.println("-------2-------" +clientSocket.isClosed());
                      System.out.println("from server__ " +inm.readLine());
             catch(IOException e){
                    e.printStackTrace();
           public void sendFile(){
                try{
                     bis = new BufferedInputStream(new FileInputStream("encryptAtmMsg.txt"));
                    bos = new BufferedOutputStream(clientSocket.getOutputStream());
                    byteArray = new byte[8192];
                    while ((in = bis.read(byteArray)) != -1){
                       bos.write(byteArray,0,in);
                        bis.close();
                      bos.close();
               catch(IOException e){
                    e.printStackTrace();
           public static void main(String[] args){
             new Client();
    }And server code is:
    import java.net.*;
    import java.io.*;
    class Server{
         BufferedInputStream bis;
           BufferedOutputStream bos;
           byte[] data;
           Socket socket;
           ServerSocket serverSocket;
           int in;
            BufferedReader inm = null;
            PrintWriter outm = null;
           public Server(){
             try{
                    serverSocket = new ServerSocket(9632);
                    System.out.println("i am server & listening...");
                   socket = serverSocket.accept();
                     System.out.println("a client connect");
                   System.out.println("------1--------" +socket.isClosed());
                    inm = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                    outm = new PrintWriter(socket.getOutputStream(), true);
                   System.out.println("from client: " +inm.readLine());
                     outm.println("ack 1: hi....");
                     System.out.println("from client: " +inm.readLine());
                     outm.println("ack 2: ok....");
                    receiveFile();
                      System.out.println("------2--------" +socket.isClosed());
                   outm.println("ack 3: take the file");
             catch (IOException e){
                  e.printStackTrace();
         public void receiveFile(){
              try{
                  byte[] receivedData = new byte[8192];
                 bis = new BufferedInputStream(socket.getInputStream());
                   bos = new BufferedOutputStream(new FileOutputStream("encryptAtmMsg22.txt"));
                 while ((in = bis.read(receivedData)) != -1){
                       bos.write(receivedData,0,in);
                 bos.close();
             catch (IOException e){
                  e.printStackTrace();
         public static void main(String[] args){
             new Server();
    }any idea pls

  • "Cannot send message using the server....."

    Hi all,
    Considering the nature of the problem I am about to relate I would have to say at the outset that I would be very very surprised if other people have not come across this problem, so here goes...
    We have around 60 users of Apple Mail from both 10.4 and 10.5, so varying degrees of versions of Apple Mail however most if not all are updated to 10.4.11 and 10.5.2.
    We have been plagued with people being frustrated about emails bouncing back with an immediate error which is basically the following...
    "Cannot send message using the server smtp.xxx.com:user
    Sending the message content to the server failed.
    Select a different outgoing mail server from the list below etc etc"
    I am sure a lot of you have seen this error.
    However, it is totally random but I am at the end of my tether with it. It generally revolves around emails with attachments and can be totally random. I was trying to send a screenshot today, very small screenshot, using the Apple-Shift-4 technique, sent the .png file, then saved it out as a .jpg, nothing. Tiny file, around 5k. Got the error above, took it out, sent no problem. Other similar files on the desktop refused to send but a .pdf did. I then thought it might be our server, so sent teh same attachments using my .mac account. Same result and failed to send. Reports from other users in our group show that they too get random results, maybe moving the attachment in the email makes it go, sometimes putting it before your signature, sometimes putting your signature copied and pasted in so many times makes it work, all sorts of methods but all resulting in the same conclusion, Apple Mail can be very unreliable.
    We have even migrated some users to Entourage and the problem disappears. Even to Thunderbird, but those users miss the search capability as it is quicker and more reliable. So they want to go back.
    Considering I have been struggling with this issue back in the day when we were on the Apple Mail related version in 10.4 I was hoping that the version released in 10.5 would remedy the problems. Sometimes I feel it has just got worse.
    Is anyone else experiencing this sort of difficulty in Apple Mail, I really feel isolated and at a loss with how to remedy this for so many users.
    If anyone can share their experiences and how they have got around similar issues in Mail I am all ears and open to any suggestions.
    Thanks everyone for taking the time to read through this. There is more but the experiences are so random it is not worth trying to put it all down.
    Thanks again.
    Gerry McCoy

    I went in to Connection Doctor and. oddly enough, for this Mac account it said I was on Port 25. Si I changed it to Port 587 and saved the changes.
    Still, I have the same problem with the same error messages.
    I go back to the mail preferences > Accounts > Advanced and it shows Port 143 still there grayed out.
    What about SSL - it's not checked.
    Odd that this problem only seems to be from one .mac account emailing to another .mac account. Could the server be down?

Maybe you are looking for

  • Best way to get SharePoint workflow to trigger InDesign XML refresh and PDF export?

    What is the best way to get a SharePoint workflow to trigger the refresh of an XML datasource within an InDesign document, and generate a PDF export? The datasource would be hosted by SharePoint. Would InDesign Server be required?

  • Copy text from action description to following acitivity

    Hello, I'm using the opportunity with sales methodology and I've created my own action profile. In the actions in the action profile, I've entered an action description text. In the opportunity, I use the sales assistant and there I can see the actio

  • Other language features

    For these language features I should probably start a JSR, however, I want the opinion of the public for it. 1) Language construct "alias" Many classes with different names do things which are nearly 100% the same. For example the Point and Dimension

  • Disable "Do not show my picture" on Lync client

    Hi all, is it possible to disable the "Do not show my picture" on Lync client ? I want to stop that an user can disable photo. Thanks a lot

  • Delimit in infotype 105

    When an employee status is withdrawn in infotype 0, then his user id(subtype 0001) is automatically delimted in infotype 105. However it does not delimit a custom subtype in infotype 105. Plz let me know on how to acheive this.