0

EDIT1: I've tried it in win7x86 and it worked. It definitely sounds it's a x64 problem... How can I send a TCP socket "x86" style in a windows x64 machine?

EDIT2: Attached the *.pcap files instead of the screenshots as @RemyLebeau kindly asked.

I have this text string to be sent to a printer, it needs no line feed/CRLF/etc to understand the code, meaning that, after every word arrived at the other side it prints.

The printer is RS232 but I'm using an Advantech ADAM4577 Ethernet-RS232 gateway to convert the signal. All I should do is open a TCP connection to the gateway and spit the string, which is this one:

  ^XA~TA000~JSN^LT0^MMT^MNW^MTT^PON^PMN^LH0,0^JMA^PR3,3^MD10^JUS^LRN^CI0^XZ
  ^XA^LL0168
  ^PW272
  ^FT61,34^A0N,28,28^FH\^FD2053200863^FS
  ^BY2,3,91^FT47,138^BCN,,Y,N
  ^FD>;9678130580^FS
  ^PQ1,0,1,Y^XZ

I'm using Delphi so I've tried TClientSocket:

unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, System.Win.ScktComp, Vcl.StdCtrls;

type
  TForm2 = class(TForm)
    Button1: TButton;
    ClientSocket1: TClientSocket;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket;
      ErrorEvent: TErrorEvent; var ErrorCode: Integer);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
  if not ClientSocket1.Active then
  begin
    ClientSocket1.Port := 9100;
    ClientSocket1.Host := '10.6.2.140';
    ClientSocket1.Address := '10.6.2.140';
    ClientSocket1.ClientType := ctNonBlocking;
    ClientSocket1.Open;
  end;

end;

procedure TForm2.Button2Click(Sender: TObject);
var
  zcode : string;
begin
 zcode :=  '^XA~TA000~JSN^LT0^MMT^MNW^MTT^PON^PMN^LH0,0^JMA^PR3,3^MD10^JUS^LRN^CI0^XZ' +
            '^XA^LL0168' +
            '^PW272' +
            '^FT61,34^A0N,28,28^FH\^FD2053200863^FS' +
            '^BY2,3,91^FT47,138^BCN,,Y,N' +
            '^FD>;9678130580^FS' +
            '^PQ1,0,1,Y^XZ';

  ClientSocket1.Socket.SendText(zcode);
end;

procedure TForm2.ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket;
  ErrorEvent: TErrorEvent; var ErrorCode: Integer);
begin
      ShowMessage(IntToStr(ErrorCode));
      ErrorCode := 0;
end;

end.

After some time I get:

Socket Error 10053 (WSAECONNABORTED)

Here is the filtered pcap file in the x64 machine: link

Exact same program, x86: link

Same text with TIdClientSocket: (UsaNagle is defaulted as true, IpVersion is IPv4

unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdBaseComponent, IdComponent,
  IdTCPConnection, IdTCPClient, Vcl.StdCtrls;

type
  TForm2 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    IdTCPClient1: TIdTCPClient;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
  if not IdTCPClient1.Connected then
  begin
    IdTCPClient1.Host := '10.6.2.140';
    IdTCPClient1.Port := 9100;
    idTCPClient1.Connect;
  end;


end;

procedure TForm2.Button2Click(Sender: TObject);
var
  zcode : string;
begin
 zcode :=  '^XA~TA000~JSN^LT0^MMT^MNW^MTT^PON^PMN^LH0,0^JMA^PR3,3^MD10^JUS^LRN^CI0^XZ' +
            '^XA^LL0168' +
            '^PW272' +
            '^FT61,34^A0N,28,28^FH\^FD2053200863^FS' +
            '^BY2,3,91^FT47,138^BCN,,Y,N' +
            '^FD>;9678130580^FS' +
            '^PQ1,0,1,Y^XZ';

  IdTCPClient1.IOHandler.WriteLn(zcode);
end;

end.

pcap file, x64: link

Exact same program, x86: link

5
  • Your screenshots are useless and impossible to read. Export the captures to .pcap files so other people can actually open and look at them. Sep 12, 2013 at 18:44
  • @RemyLebeau Edited as you requested. Thanks in advance!
    – IgorMF
    Sep 13, 2013 at 15:39
  • 1
    Next time, pre-filter the .pcap files yourself. You don't have to export everything that was captured, you can export filtered data. Sep 13, 2013 at 19:31
  • Indy's WriteLn() sends a CRLF after the text. TClientSocket's SendText() does not. Use Indy's Write() instead to match TClientSocket's behavior. Sep 16, 2013 at 21:10
  • Thanks, tried with Write(), same results. The printer itself doesn't care about the extra CRLF anyway :)
    – IgorMF
    Sep 17, 2013 at 0:21

1 Answer 1

1

According to the .pcap files:

The WinXPx86 system is doing the following:

Sends:

^

which is ACK'ed, then sends:

XA~TA000~JSN^LT0^MMT^MNW^MTT^PON^PMN^LH0,0^JM

Which is ACK'ed, then sends:

A^PR3,3^MD10^JUS^LRN^CI0^XZ^XA^LL0168^PW272^FT61,34^A0N,28,28^FH\^FD2053200863^FS^BY2,3,91^FT47,138^BCN,,Y,N^FD>;9678130580^FS^PQ1,0,1,Y^XZ

Which is ACK'ed, then disconnects.

On the other hand, the Win7x64 system is doing the following:

Sends:

^

Which is ACK'ed, then sends:

XA~TA000~JSN^LT0^MMT^MNW^MTT^PON^PMN^LH0,0^JMA^PR3,3^MD10^JUS^LRN^CI0^XZ^XA^LL

but disconnects before it is ACK'ed.

Up to the ^LL portion, they are sending the exact data data. However, this activity suggests to me that:

  1. your x86 and x64 code may or may not be using the same code logic, since they are sending the same TCP data with different framing (although that may just be related to the Nagle algorithm used internally by the sockets).

  2. on Win7x64, the socket is being disconnected prematurely, which is likely a coding issue, such as if you are closing the TClientSocket too early in reaction to some error your code is encountering.

Without seeing your actual code, there is no way to troubleshoot this issue further. Otherwise, you should add some logging to your code so you know what it is actually doing at each step (like when and why it is closing the socket).

5
  • Remy, thanks for the insight! However, Those dumps are not from a Delphi program, they are from Hyperterminal's "Send text file".
    – IgorMF
    Sep 13, 2013 at 20:38
  • If HyperTerminal is having problems under x64, then it is likely just a buggy x64 implementation. You said you were having a similar problem in your Delphi code, which you have control over, so please show that code. You said you were using TClientSocket, do you have the same problem with other socket libraries, like Indy, ICS, or Synapse? I find it very hard to believe that WinSock itself would be so buggy. Sep 13, 2013 at 20:58
  • Really apreciated your help so far. I'd Never think it could be a buggy hyperterminal, oh well! I've attached new files and code for ClientSocket and IdTCPClient. As you can see, they both turn out to work in x86 and not work in x64 exactly the same. I also tried setting UseNagle to false on IdTCPClient and it didn't change.
    – IgorMF
    Sep 16, 2013 at 20:29
  • 1
    Looking at the latest .pcap files, the only real difference I see beteen them is that the x64 TCP headers are 12 bytes larger than then x86 TCP headers. x64 is specifying additional TCP options that x86 is not. Maybe your RS232 gateway device is not handling those extra bytes correctly. I would suggest you setup a separate echo server and connect your x86 and x64 clients to it. Make sure it is able to receive the client requests correctly. If it does, then your problem is definitely related to a problem with the RS232 gateway device. Sep 16, 2013 at 21:15
  • Is there a way I can force my system to use headers the same size as the x86 machine? How can I possibly make this "backward compatible"? The problem is definitely the gateway, but what if I couldn't just switch the hardware?
    – IgorMF
    Sep 17, 2013 at 0:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.