Question

JAVA socket problem. need equivalent to a socket.shutdownOutput()

Asked by: dmiyatake

Greetings,

I am in dire need of help to get this code to work in a JDK 1.1, 1.2 platform...  The following code connects to a fedex server and uploads a string of data and then returns the servers response.  This definately works right now on 1.4.2 on my local machine,  however I need to use this in Oracle 8i which has an older version of Java (1.2 or 1.1)...

The socket.shutdownOutput() method does not exist in this version.  Without explicitly shutting down the output, the server keeps waiting for more data and never sends a resopnse.

I have looked all over google and ee for suggetions and answersa and nothing has worked.  I have no ability to modify the serverside of this!

I have also tried to do this in PL/SQL via UTL_TCP with the same issue.  However, there is no equivalent to the socket.shutdownOutput(); method so it just sits there like a lazy dog boy.


I need a way to get this functioning!!!

HELP!

import java.net.*;
import java.io.*;

public class xxxTTT {
    public static void main (String[] args) throws Exception {
    try {
         
         char dq = (char)34;
         String data = "example"
        String hostname = "xx.xx.xx.xx";
        int port = 2000;
        InetAddress addr = InetAddress.getByName(hostname);
        Socket socket = new Socket(addr, port);
       
       
        // Specify the timeout.
        socket.setSoTimeout(5000);
       
          // Send data to socket
        PrintWriter wr = new PrintWriter(socket.getOutputStream(), true);
        wr.println(data);
        wr.flush();

         socket.shutdownOutput();
     
           // Get response from the fed ex server!
      BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream()));

       String line;
        while ((line = rd.readLine()) != null)
         {
              System.out.println(line);
           }
       
        wr.close();
        rd.close();
         socket.close();
    } catch (Exception e)
        {
             System.out.println(e);
         }
         
  }
}

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-10-03 at 14:01:48ID21582490
Tags

java

,

socket

,

utl_tcp

Topic

Java Programming Language

Participating Experts
3
Points
500
Comments
53

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. JDK 1.2.2 Compiler Issue
    I installed JDK 1.2.2 last evening and created a simple "Hello World!" application. The code for this app is .. class HelloWorldApp { public static void main(String[] args) { System.out.printIn("Hello World!"); } } When I compile this code, howev...
  2. void printarray (int arg[], int length)
    // arrays as parameters #include <iostream.h> Can someone explain the following code for me. so u initial n, and when n is less than length do you cout<< arg[] or n++?? void printarray (int arg[], int length) { for (int n=0; n<length; n++) cout <&l...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: CEHJPosted on 2005-10-03 at 14:04:42ID: 15009893

Try just closing the output stream. You need a reference to it first though

 

by: dmiyatakePosted on 2005-10-03 at 14:12:05ID: 15009963

What do you mean by reference?

 

by: matthewdflemingPosted on 2005-10-03 at 14:14:21ID: 15009976

That stinks there isn't a special character you can send to say you are done sending.. Did you try socket.setSoLinger()?

 

by: matthewdflemingPosted on 2005-10-03 at 14:16:10ID: 15009987

OutputStream output = socket.getOutputStream();
PrintWriter wr = new PrintWriter(output, true);
        wr.println(data);
        wr.flush();

         socket.shutdownOutput();
output.close();

 

by: CEHJPosted on 2005-10-03 at 14:16:14ID: 15009989

>> PrintWriter wr = new PrintWriter(socket.getOutputStream(), true);

-->

OutputStream out = socket.getOutputStream();
PrintWriter wr = new PrintWriter(out, true);

......

out.close();

 

by: matthewdflemingPosted on 2005-10-03 at 14:16:40ID: 15009997

without the shutdownOutput() I meant..

 

by: dmiyatakePosted on 2005-10-03 at 14:19:26ID: 15010024

I tried it to no avail...

 

by: matthewdflemingPosted on 2005-10-03 at 14:24:23ID: 15010062

Did you try the linger as well?

 

by: dmiyatakePosted on 2005-10-03 at 14:26:04ID: 15010073

Ok,

I tried both suggestions and neither work... when closing the reference (out.close), it closes the socket and I have nothing to read.  I am attaching the modified source...  It will work by commenting the out.close and using the shutdownOutput() though...

import java.net.*;
import java.io.*;
import java.lang.*;

public class XXXX {
    public static void main (String[] args) throws Exception {
    try {
          
          char dq = (char)34;
          String data = "example";
        String hostname = "XX.XX.xx.xx";
        int port = 2000;
        InetAddress addr = InetAddress.getByName(hostname);
        Socket socket = new Socket(addr, port);    
       
        // Specify the timeout.
        socket.setSoTimeout(1000);

            // Send data to socket
       // PrintWriter wr = new PrintWriter(socket.getOutputStream(), true);
        OutputStream out = socket.getOutputStream();
            PrintWriter wr = new PrintWriter(out, true);
        //wr.println(data);
        wr.println(data);
        wr.flush();
       
        out.close();

         // socket.shutdownOutput();
      
          // Get response from the fed ex server!
            BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream()));

             String line;
        while ((line = rd.readLine()) != null)
          {
                System.out.println(line);
              }
       
        wr.close();
        rd.close();
          socket.close();
          } catch (Exception e)
        {
              System.out.println(e);
          }         
  }
}

 

by: dmiyatakePosted on 2005-10-03 at 14:26:56ID: 15010084

Yes, my first response was with the linger... I tried it right after I set the timeout and also after the flush...

 

by: matthewdflemingPosted on 2005-10-03 at 14:43:20ID: 15010190

ack.. I checked out the java source for the socket and of course it is a native method for shutdownOutput().  Did you write/control the socket server?  If so just code a special character for the "stop listening and give me some output" event.  If you don't control it (I think you said it is FedEx), have you asked them "how do I get it to stop listening?"

 

by: dmiyatakePosted on 2005-10-03 at 14:46:18ID: 15010212

I guess in order for the server to see a FIN, it needs to see an EOF marker...  R there EOF markers embedded in files?  What I was thinking, is that I could somehow read an empty file with an EOF and append that to the data I am sending so the server would know that there was an end of file...

 

by: matthewdflemingPosted on 2005-10-03 at 14:49:41ID: 15010229

Just a brainstorm but I'm sure you could do something with the File class or the FileInputStream.. I would check out the source of those and see how they determine an EOF condition.. then replicate that to your outputstream..

 

by: dmiyatakePosted on 2005-10-03 at 14:51:57ID: 15010241

I am waiting for a response to see if there is some sort of termination sequence that it is expecting... However, I didn't see that evidenced in the documentation they provide online...  Here is the "sample" source code from a C version of the program they include in the Appendix...

using TCP/IP protocol.
/*
* (c) Copyright FedEx 1998-2002
*
*
* Ship Manager Business Architecture Development
* Custom Integrated Solutions
* September 1998
*
*
*
* DESCRIPTION: Sample socket client to connect to the Ship Manager Plus Server.
* Inputs: <input file> <output file>
* Outputs: <output file>
*
* COMMENTS: change the #define PSPSERVER_HOSTNAME to match the PSPServer
* hostname as defined in your /etc/hosts file.
*
* COMPILE:
* SOLARIS 2.6 cc fxrssamp.c -o fxrssamp -lnsl -lsocket
* REDHAT LINUX 7.2 cc fxrssamp.c -o fxrssamp
* WINDOWS VISUAL STUDIO 6 Be sure to include WSOCK32.lib in link
* IBM AIX 3.4 /bin/xlc_r fxrssamp.c -o fxrssamp
* HPUX 11.0 /opt/aCC/bin/aCC +W829,749 +DA1.1 fxrssamp.c -o fxrssamp
*
*/
#ifdef WIN32
#include <winsock.h>
#include <io.h>
#define CLOSE_SOCKET closesocket
#else
#include <unistd.h> /* open(), close(), write(), read() */
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <errno.h>
#define CLOSE_SOCKET close
#endif
#include <stdio.h>
#include <string.h>
/***** SET YOUR TEST HOST HERE *****/
#define PSPSERVER_HOSTNAME "yourFedExServerName.yourcompany.com"
#define PSPSERVER_PORT 2000
int ConnectPSPServer(int *sd, char *hostNm, short portNbr);
void reportError (char *str);
int main(int argc, char **argv)
{
int sd, i=0;
FILE *inFile, *outFile;
char buffer[4096];
if(argc != 3)
{
printf("USAGE: %s <trans in file> <trans out file>\n", argv[0]);
return 1;
}
printf("Test Client of FedEx Ship Manager Plus Server started.\n");
printf("Attempting to connect to: %s:%d\n", PSPSERVER_HOSTNAME, PSPSERVER_PORT);
if(!ConnectPSPServer(&sd, PSPSERVER_HOSTNAME, PSPSERVER_PORT))
{
printf("Error: Cannot connect to %s\n", PSPSERVER_HOSTNAME);
return 2;
}
printf("Connected to %s:%d\n", PSPSERVER_HOSTNAME, PSPSERVER_PORT);
inFile = fopen(argv[1], "r");
/* error checking ignored for simplicity */
outFile = fopen(argv[2], "wa");
/* error checking ignored for simplicity */
printf("Reading request transactions from: %s\n", argv[1]);
printf("Writing reply transactions to: %s \n", argv[2]);
fgets(buffer, sizeof(buffer), inFile); /* read transaction request */
while(!feof(inFile))
{
int rc;
rc=send(sd, buffer, strlen(buffer),0); /* write request to server */
if (rc < 0)
reportError("Write to server failed");
memset (buffer, 0, sizeof buffer);
rc=recv(sd, buffer, sizeof buffer,0); /* read transaction reply */
if (rc <= 0)
{
if (rc == 0)
printf ("socket was closed by server\n");
else
reportError("Reading response failed");
}
fputs(buffer, outFile); /* write reply to file */
fputc('\n', outFile);
i++;/* increase reply count */
if(i % 10 == 0)
printf("%d", i);
else
printf(".");
fflush(stdout);/* stdout normally flushes with each \n character */
fgets(buffer, sizeof(buffer), inFile); /* read transaction request */
}
fclose(outFile);
fclose(inFile);
if(CLOSE_SOCKET(sd) == 0) /* Close connection */
printf("\nConnection to %s terminated.\n", PSPSERVER_HOSTNAME);
printf("%d transactions processed.\n", i);
return 0;
}
int ConnectPSPServer(int *sd, char *hostNm, short portNbr)
{
struct hostent *hp;
struct sockaddr_in sin;
#ifdef WIN32
WORD winsock_ver;
WSADATA winsock_data;
int rc;
winsock_ver = 0x0101;
rc = WSAStartup(winsock_ver, &winsock_data);
if (rc != 0)
return 0;
#endif
/* Set up the socket descriptor and the address */
memset(&sin, 0, sizeof(struct sockaddr_in));
*sd = socket(AF_INET, SOCK_STREAM, 0);
if (*sd < 0)
{
reportError("socket call failed");
return 0;
}
hp = gethostbyname(hostNm);
if (hp == NULL)
{
reportError("gethostbyname lookup failed");
return 0;
}
memcpy(&sin.sin_addr, hp->h_addr, hp->h_length);
sin.sin_port = htons(portNbr);
sin.sin_family = hp->h_addrtype;
/* Make the connection */
if(connect(*sd, (struct sockaddr *)&sin, sizeof(struct sockaddr_in)) == -1)
{
reportError("connect to host failed");
return 0;/*FALSE*/
}
return 1;/*TRUE*/
}
void reportError (char *str)
{
int errValue;
#ifdef WIN32
errValue = WSAGetLastError();
#else
errValue = errno;
#endif
printf ("ERROR: %s [err=%d]\n", str, errValue);
return;

 

by: matthewdflemingPosted on 2005-10-03 at 14:56:12ID: 15010266

I think you're right about the EOF as the terminator.. a quick test would be to read a file and write to the output stream and make sure that everything worked appropriately.

 

by: matthewdflemingPosted on 2005-10-03 at 14:57:20ID: 15010274

not to be flip.. but I'm sure it was stuff like this that caused the shutdownOutput() to be added.. what a pain.

 

by: CEHJPosted on 2005-10-03 at 15:00:48ID: 15010289

Try

int buf = -1;
StringReader in = new StringReader(data);
while ((buf = in.read()) > -1) {
      out.write(buf);
}

 

by: matthewdflemingPosted on 2005-10-03 at 15:02:29ID: 15010300

that looks like a good call CEHJ..;-)

 

by: dmiyatakePosted on 2005-10-03 at 15:08:31ID: 15010334

I will try your suggest CEHJ,  I also have another piece of info that may help you guys help me :)  (THANKS ALOT NO MATTER WHAT!)

Anyway, when I was cutting and pasting the C code, I noticed that they allocate 4096 bytes to the write... I decided to try to fill up the buffer... and tested > 4096 and <4096

        wr.println(data); //441
        wr.println(data); //441
        wr.println(data); //441
        wr.println(data); //441
        wr.println(data); //441
        wr.println(data); //441
        wr.println(data); //441
        wr.println(data); //441
        wr.println(data); //441
        wr.println(data); //441
        // total buffer size 4410 //
        System.out.println("*** 1 ***");

The end result was that if I run this code "no close or setoutputoff... It works, albeit strangely since I am sending mutliple requests...  Anyway, I think I may need to just fill up the buffer with  4096 - data.length() empty spaces or garbage character...

If one of you could help me with that code ( I AM TOTALLY NOT A JAVA PROGRAMMER) it would be awesome!


import java.net.*;
import java.io.*;
import java.lang.*;

public class XXXedex {
    public static void main (String[] args) throws Exception {
    try {
          
          char dq = (char)34;
          String data = "test";
        String hostname = "XXXXX5";
        int port = 2000;
        InetAddress addr = InetAddress.getByName(hostname);
        Socket socket = new Socket(addr, port);    
       
        // Specify the timeout.
        socket.setSoTimeout(1000);
       
       // Send data to socket
       // PrintWriter wr = new PrintWriter(socket.getOutputStream(), true);
        OutputStream out = socket.getOutputStream();
            PrintWriter wr = new PrintWriter(out, true);
        wr.println(data); //441
        wr.println(data); //441
        wr.println(data); //441
        wr.println(data); //441
        wr.println(data); //441
        wr.println(data); //441
        wr.println(data); //441
        wr.println(data); //441
        wr.println(data); //441
        wr.println(data); //441
        // total buffer size 4410 //
        System.out.println("*** 1 ***");
            
        wr.flush();
       
   
       // out.close();

         //socket.shutdownOutput();
      
          // Get response from the fed ex server!
            BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream()));

             String line;
        while ((line = rd.readLine()) != null)
          {
                System.out.println(line);
              }
       
        wr.close();
        rd.close();
          socket.close();
          } catch (Exception e)
        {
              System.out.println(e);
          }
          
  }
}

 

by: CEHJPosted on 2005-10-03 at 15:14:20ID: 15010370

I'm not sure that the size of the buffer is significant

 

by: dmiyatakePosted on 2005-10-03 at 15:25:15ID: 15010416

Ok, I am trying your last suggestion CEHJ... Forgive my ignorance but where exactly should I include that... I am asuming that will handle the write to the server... but it looks like out.write(buf) will be numeric...

Forgive me in advance! :)

 

by: objectsPosted on 2005-10-03 at 15:31:22ID: 15010444

> Anyway, I think I may need to just fill up the buffer with  4096 - data.length() empty spaces or garbage character...

if you create a 4096 byte buffer it will be full of )'s by default.
You can use the Arrays.fill() method to fill it whatever you need.

 

by: objectsPosted on 2005-10-03 at 15:43:08ID: 15010499

Would look something like this (data is the string you want to pass):

byte[] bytes = data.getBytes();
byte[] buf = new byte[4096];
Arrays.fill(buf, 0);  // youcould also try spaces
System.arraycopy(bytes, 0, buf, 0, bytes.length);


 

by: objectsPosted on 2005-10-03 at 15:57:44ID: 15010555

Looks like filling the buffer should fix your problem.

 

by: CEHJPosted on 2005-10-04 at 03:04:22ID: 15012596

There should be no need to be writing empty buffers redundantly to fix the problem.

It's conceivable that a null-termination is expected, so also try

int buf = -1;
StringReader in = new StringReader(data);
while ((buf = in.read()) > -1) {
     out.write(buf);
}
out.write(0);

 

by: dmiyatakePosted on 2005-10-04 at 06:19:20ID: 15013551

CEHJ and others,

I am having trouble witht that last bit of code... when I print the output (buf) it is numeric data...  The data string is definately not...  I am going to take a look at this right now, any quick answers would be greatly appreciated.

thanks!

 

by: CEHJPosted on 2005-10-04 at 06:21:11ID: 15013570

You just need to substitute it for the code sending that 'data' String

 

by: CEHJPosted on 2005-10-04 at 06:22:45ID: 15013585

>>when I print the output (buf) it is numeric data...

You needn't worry about that. If you want to print it, cast it to char

 

by: dmiyatakePosted on 2005-10-04 at 06:43:05ID: 15013752

Ok, got it... Bad news is that this also works if you use the shutdownOutput statement. I tried it sans the out.write(0) as well...  Any other suggestions???

     // Send data to socket
       OutputStream out = socket.getOutputStream();
   
            int buf = -1;
            StringReader in = new StringReader(data);
            while ((buf = in.read()) > -1) {
                 out.write(buf);
                  }
          out.write(0);
        //out.close();

       //socket.shutdownOutput();

 

by: CEHJPosted on 2005-10-04 at 06:47:24ID: 15013792

Try

out.write(0);
out.write("\r\n".getBytes());

 

by: matthewdflemingPosted on 2005-10-04 at 06:50:43ID: 15013822

Right so have you tried taking your data as a file and reading the file to that output? The socket server isn't getting the termination character that it wants.. I think that is what you should be striving to find.  Do you have a contact at fedex that you could ask about this?  

 

by: dmiyatakePosted on 2005-10-04 at 06:52:20ID: 15013837

Nada...  Still works with the  shutdownOutput() thought :(

 

by: dmiyatakePosted on 2005-10-04 at 06:58:21ID: 15013909

I have a contact that is researching...  I think they will probably come back with the suggestion to write it in C...  I will try the file idea right now and post.

 

by: dmiyatakePosted on 2005-10-04 at 07:18:21ID: 15014143

tried to but the data in a file and pass... it doesn't work.. tried most comb/perms of file encoding  and term characters... also pc and dos.

 

by: CEHJPosted on 2005-10-04 at 07:24:33ID: 15014216

>>I think they will probably come back with the suggestion to write it in C..

Don't let them palm you off with that ;-) It should be doable in Java

 

by: dmiyatakePosted on 2005-10-04 at 08:27:49ID: 15014840

I just finished with fed-ex support...  I don't know if support is really the term that applies :)!  Anyway, they had no suggestion to help... The 99,"" is a termination sequence that is expected by the server... Using the shutdownOutput command, I receive a response and that can only happen if the transaction is complete which demonstrates that my test transaction is syntactically correct.

I am really at a loss...

 

by: CEHJPosted on 2005-10-04 at 09:09:50ID: 15015224

>>The 99,"" is a termination sequence that is expected by the server

Don't quite understand this ...

 

by: matthewdflemingPosted on 2005-10-04 at 09:18:15ID: 15015300

Wait if you send the characters 99,"" fedex calls the transaction complete?  The "file" you are sending to them has a published spec right?  That file must have some type of "end" record.. which means that if you are sending the file in the right format the socket shouldn't have to be shutdown to start receiving a response.  Is there anyway you can ask them to give you a debugish environment. Can you confirm with them what they are actually receiving?  Maybe there is some stupid encoding problem?

 

by: dmiyatakePosted on 2005-10-04 at 09:20:02ID: 15015323

The transaction I send has a specific format. The sequence 99,"" is a terminator for a transaction.  The fact that I am getting a valid response indicates that my transaction contains is valid as defined by fed-ex.

The support person i spoke to says that 99,"" is the terminator the server is looking for... I can conclusively show that my transaction contains the terminator and the failure to respond is not due to a malformed transaction...

This just takes us back to the fact that without the shutdownOutput method, I can't get the reply...

 

by: matthewdflemingPosted on 2005-10-04 at 09:22:58ID: 15015359

Okay so are you certain that fedex is receiving the 99,"" terminator?  If not, the shutdownOutput method could merely be doing something like a buffer flush (I know you have the flush in your code) at a lower level.  I would make sure that they are receiving what you think they are.  You could snoop the tcp packets and confirm you are sending what you think you are, if they can't help you.

 

by: objectsPosted on 2005-10-04 at 14:11:48ID: 15017798

Did you try the code I posted above?

 

by: objectsPosted on 2005-10-04 at 14:14:59ID: 15017819

byte[] bytes = data.getBytes();
byte[] buf = new byte[4096];
Arrays.fill(buf, 0);  // youcould also try spaces
System.arraycopy(bytes, 0, buf, 0, bytes.length);
out.write(buf);

 

by: CEHJPosted on 2005-10-04 at 14:15:59ID: 15017828

>>The sequence 99,"" is a terminator for a transaction.

In that case, writing to the stream with \r\n is possibly 'undoing' the termination

 

by: CEHJPosted on 2005-10-04 at 14:20:17ID: 15017861

Try

out.write("test  99,\"\"".getBytes());
out.flush();

*not* println

 

by: objectsPosted on 2005-10-04 at 14:21:43ID: 15017870

You should not be using a PrintWriter at all in fact :)

 

by: dmiyatakePosted on 2005-10-06 at 15:40:38ID: 15034838

I am changing the printwriter code when I get the chance... It works but it leaves a strange termination character I don't like.  Anyway, I split the points again because I found everyones help very usefull.  The solution was actually very simple and I am happy it is behind me.

The error turned out to be on the read of the response.  Using what I learned from CEHJ

int buf = -1;
StringReader in = new StringReader(data);
while ((buf = in.read()) > -1) {
     out.write(buf);
}
out.write(0);

I  modified this to see the effect of the multiple sends I did when I saw a resposne.  I realized by seeing the ascii stream coming back that the termination was not what I expected.  I then corrected it and it has been working great ever since!!!

You all rock!

 

by: objectsPosted on 2005-10-06 at 15:49:56ID: 15034883

You don't need to use a StringReader (that approach will be pretty slow), see the code I posted earlier :)

 

by: matthewdflemingPosted on 2005-10-07 at 06:47:53ID: 15038582

Glad to hear it..

 

by: matthewdflemingPosted on 2005-10-07 at 06:48:58ID: 15038593

that you solved the problem I mean.. It is usually challenging to find the real problem.. the solution is usually pretty easy once you find it.

 

by: matthewdflemingPosted on 2005-12-29 at 07:07:16ID: 15570781

dmiyatake: "Anyway, I split the points again because I found everyones help very usefull.  The solution was actually very simple and I am happy it is behind me."

I think you should split it among the three of us: objects, cehj and me.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...