IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

SEND STREAM - UTF8 - BIG ENDIAN - SOH


Sujet :

VB.NET

  1. #1
    Membre averti
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2011
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Finance

    Informations forums :
    Inscription : Mai 2011
    Messages : 13
    Par défaut SEND STREAM - UTF8 - BIG ENDIAN - SOH
    Bonjour
    j'essaie de traduire le texte ci-dessous en vb.net mais ca ne fonctionne pas, pas d'erreur de compilation mais le serveur ne reçoit rien

    The Payment Terminal uses utf-8 encoding.
    Basic message transport information is added to the XML messages shown in this chapter. In order to send and receive variable length XML messages a simple message header indicating the overall length of the message must be used.
    The XML messages starts with a 4 Byte unsigned integer used as length indicator (big endian format, i.e. most significant byte first). There is no 0x00 at the end of the message included.
    The XML message below has a length of 544 characters when converted to bytes.

    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <?xml version="1.0" encoding="utf-8"?>
    <CardServiceRequest WorkstationID="POS" RequestID="205" RequestType="CardPayment" xmlns="http://www.nrf-arts.org/IXRetail/namespace">
    <POSdata LanguageCode="nl">
    <POSTimeStamp>2015-09-16T14:08:34.8279797+02:00</POSTimeStamp>
    <ShiftNumber>0</ShiftNumber>
    <PrinterStatus>Available</PrinterStatus>
    <E-JournalStatus>Available</E-JournalStatus>
    </POSdata>
    <TotalAmount Currency="EUR">0.01</TotalAmount>
    <CardCircuitCollection>
    </CardCircuitCollection>
    </CardServiceRequest>


    This length of this message is 544 bytes and will be preceded by a 4 bytes length: 00 00 02 20 (= 544 decimal)
    The whole message will look like:

    000000: 0000 0220 3c3f 786d 6c20 7665 7273 696f      ... <?xml versio
    000010: 6e3d 2231 2e30 2220 656e 636f 6469 6e67     n="1.0" encoding
    000020: 3d22 7574 662d 3822 3f3e 0d0a 3c43 6172     ="utf-8"?>..<Car
    000030: 6453 6572 7669 6365 5265 7175 6573 7420     dServiceRequest
    000040: 576f 726b 7374 6174 696f 6e49 443d 2250     WorkstationID="P
    000050: 4f53 2220 5265 7175 6573 7449 443d 2232    OS" RequestID="2
    000060: 3035 2220 5265 7175 6573 7454 7970 653d    05" RequestType=
    000070: 2243 6172 6450 6179 6d65 6e74 2220 786d    "CardPayment" xm
    000080: 6c6e 733d 2268 7474 703a 2f2f 7777 772e      lns="http://www.
    000090: 6e72 662d 6172 7473 2e6f 7267 2f49 5852      nrf-arts.org/IXR
    0000a0: 6574 6169 6c2f 6e61 6d65 7370 6163 6522     etail/namespace"
    0000b0: 3e0d 0a20 203c 504f 5364 6174 6120 4c61     >.. <POSdata La
    0000c0: 6e67 7561 6765 436f 6465 3d22 6e6c 223e     nguageCode="nl">
    0000d0: 0d0a 2020 2020 3c50 4f53 5469 6d65 5374     .. <POSTimeSt
    0000e0: 616d 703e 3230 3135 2d30 392d 3136 5431     amp>2015-09-16T1
    0000f0: 343a 3038 3a33 342e 3832 3739 3739 372b     4:08:34.8279797+
    000100: 3032 3a30 303c 2f50 4f53 5469 6d65 5374      02:00</POSTimeSt
    000110: 616d 703e 0d0a 2020 2020 3c53 6869 6674    amp>.. <Shift

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
                Dim SizeMSG As UInt32 = 544 ' EXEMPLE : longueur du MESSAGE a envoyer
                Dim HEADER = ChrW(&H1) & SizeMSG   ' ChrW(&H1) = SOH -> unicode header ( alt+001 )
                Dim vecteur1As Byte() = System.Text.Encoding.BigEndianUnicode.GetBytes(HEADER)
     
                Dim vecteur2 As Byte() = System.Text.Encoding.UTF8.GetBytes("MESSAGE XML A ENVOYER")
     
                Dim COPYTAB As Byte()
                ReDim COPYTAB(vecteur1.Length + vecteur2.Length) 
                System.Array.Copy(vecteur1, 0, COPYTAB, 0, vecteur.Length)
                System.Array.Copy(vecteur2, 0, COPYTAB, vecteur.Length, vecteur2.Length)
     
               Dim client As New System.Net.Sockets.TcpClient()
               client = New System.Net.Sockets.TcpClient
               client.Connect(IP, port)
     
              Dim sendStream As NetworkStream = client.GetStream()
              sendStream .Write(COPYTAB, 0, COPYTAB.Length)
              sendStream .Flush()

    Ai je bien fait ???

    Merci d'avance pour votre aide

  2. #2
    Membre averti
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2011
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Finance

    Informations forums :
    Inscription : Mai 2011
    Messages : 13
    Par défaut
    Voici une réponse du Terminal à titre d'exemple

    XML envoyé par le Terminal

    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    <?xml version="1.0" encoding="utf-8"?>
    <CardServiceRequest WorkstationID="POS1" POPID="1" RequestID="122" RequestType="CardPayment" xmlns="http://www.nrf-arts.org/IXRetail/namespace">
      <POSdata LanguageCode="fr" RequestTransactionInformation="true">
        <POSTimeStamp>2021-03-16T22:36:16.5374314+01:00</POSTimeStamp>
        <ShiftNumber>0</ShiftNumber>
        <PrinterStatus>Available</PrinterStatus>
        <JournalPrinterStatus>Available</JournalPrinterStatus>
      </POSdata>
      <TotalAmount Currency="EUR">0.01</TotalAmount>
      <CardCircuitCollection />
    </CardServiceRequest>

    Socket envoyé ( taille du XML 580 - 4 ) = 0240 hexadecimal --> En tête du message il y a ceci : ...@ ( le @ est le unicode ascii de 0240 hexadecimal )
    Parfois il y a le code "SOH" à la place des ...

    Data length: 580 (580-4)
    000000: 0000 0240 3c3f 786d 6c20 7665 7273 696f  ...@<?xml versio
    000010: 6e3d 2231 2e30 2220 656e 636f 6469 6e67  n="1.0" encoding
    000020: 3d22 7574 662d 3822 3f3e 0d0a 3c43 6172  ="utf-8"?>..<Car
    000030: 6453 6572 7669 6365 5265 7175 6573 7420  dServiceRequest 
    000040: 576f 726b 7374 6174 696f 6e49 443d 2250  WorkstationID="P
    000050: 4f53 3122 2050 4f50 4944 3d22 3122 2052  OS1" POPID="1" R
    000060: 6571 7565 7374 4944 3d22 3132 3222 2052  equestID="122" R
    000070: 6571 7565 7374 5479 7065 3d22 4361 7264  equestType="Card
    000080: 5061 796d 656e 7422 2078 6d6c 6e73 3d22  Payment" xmlns="
    000090: 6874 7470 3a2f 2f77 7777 2e6e 7266 2d61  http://www.nrf-a
    0000a0: 7274 732e 6f72 672f 4958 5265 7461 696c  rts.org/IXRetail
    0000b0: 2f6e 616d 6573 7061 6365 223e 0d0a 2020  /namespace">..  
    0000c0: 3c50 4f53 6461 7461 204c 616e 6775 6167  <POSdata Languag
    0000d0: 6543 6f64 653d 2266 7222 2052 6571 7565  eCode="fr" Reque
    0000e0: 7374 5472 616e 7361 6374 696f 6e49 6e66  stTransactionInf
    0000f0: 6f72 6d61 7469 6f6e 3d22 7472 7565 223e  ormation="true">
    000100: 0d0a 2020 2020 3c50 4f53 5469 6d65 5374  ..    <POSTimeSt
    000110: 616d 703e 3230 3231 2d30 332d 3136 5432  amp>2021-03-16T2
    000120: 323a 3336 3a31 362e 3533 3734 3331 342b  2:36:16.5374314+
    000130: 3031 3a30 303c 2f50 4f53 5469 6d65 5374  01:00</POSTimeSt
    000140: 616d 703e 0d0a 2020 2020 3c53 6869 6674  amp>..    <Shift
    000150: 4e75 6d62 6572 3e30 3c2f 5368 6966 744e  Number>0</ShiftN
    000160: 756d 6265 723e 0d0a 2020 2020 3c50 7269  umber>..    <Pri
    000170: 6e74 6572 5374 6174 7573 3e41 7661 696c  nterStatus>Avail
    000180: 6162 6c65 3c2f 5072 696e 7465 7253 7461  able</PrinterSta
    000190: 7475 733e 0d0a 2020 2020 3c4a 6f75 726e  tus>..    <Journ
    0001a0: 616c 5072 696e 7465 7253 7461 7475 733e  alPrinterStatus>
    0001b0: 4176 6169 6c61 626c 653c 2f4a 6f75 726e  Available</Journ
    0001c0: 616c 5072 696e 7465 7253 7461 7475 733e  alPrinterStatus>
    0001d0: 0d0a 2020 3c2f 504f 5364 6174 613e 0d0a  ..  </POSdata>..
    0001e0: 2020 3c54 6f74 616c 416d 6f75 6e74 2043    <TotalAmount C
    0001f0: 7572 7265 6e63 793d 2245 5552 223e 302e  urrency="EUR">0.
    000200: 3031 3c2f 546f 7461 6c41 6d6f 756e 743e  01</TotalAmount>
    000210: 0d0a 2020 3c43 6172 6443 6972 6375 6974  ..  <CardCircuit
    000220: 436f 6c6c 6563 7469 6f6e 202f 3e0d 0a3c  Collection />..<
    000230: 2f43 6172 6453 6572 7669 6365 5265 7175  /CardServiceRequ
    000240: 6573 743e                                                   est>
    Code utilisé :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    dim sizemsg0 = 580 - 4
            Dim hexString = Hex(sizemsg0) 'hexa
            Dim hexS As String = sizemsg0.ToString("X4")
            hexS = hexS & ""
            Dim HEXAbyte As Byte() = System.Text.Encoding.UTF8.GetBytes(hexS)
            Dim fin22 = hex2ascii2(hexS)
     
           résultat -> fin22 = "  @"
     
        Function hex2ascii2(ByVal hextext As String) As String
            Dim value
            For y = 1 To Len(hextext)
                Dim num = Mid(hextext, y, 2)
                value = value & Chr(Val("&h" & num))
                y = y + 1
            Next y
     
            Return value
        End Function

  3. #3
    Invité
    Invité(e)
    Par défaut
    Salut

    Ta demande n'est pas très claire, tu envois et/ou tu reçois?
    D'après ce message : Basic message transport information is added to the XML messages shown in this chapter.
    Si tu réceptionne les données, je le traiterais comme un vulgaire xml.

  4. #4
    Membre averti
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2011
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Finance

    Informations forums :
    Inscription : Mai 2011
    Messages : 13
    Par défaut
    je pense que c'est comme ceci mais le terminal ne reçoit toujours rien.

    peut être que je dois envoyer d'une autre manière ?

    mais ce code converti bien

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
     
             Dim ret As String = Nothing
            Dim msgBytes As Byte() = encoding.GetBytes(msg)
     
             Dim totalMessageLength As UInteger  '  - 4
            Dim msgLengthBytes As Byte() = BitConverter.GetBytes(totalMessageLength)
            Array.Reverse(msgLengthBytes)
     
            Dim COPYTAB As Byte()
            ReDim COPYTAB(msgLengthBytes.Length + msgBytes.Length) '+ outStream.Length
            System.Array.Copy(msgLengthBytes, 0, COPYTAB, 0, msgLengthBytes.Length)
            System.Array.Copy(msgBytes, 0, COPYTAB, msgLengthBytes.Length, msgBytes.Length)
     
            Dim convertionUTF8 = System.Text.Encoding.UTF8.GetString(COPYTAB)
     
            strm.Write(COPYTAB, 0, COPYTAB.Length)
            strm.Flush()
     
            Application.Exit()

Discussions similaires

  1. Conversion little vers big endian
    Par kris1980 dans le forum x86 32-bits / 64-bits
    Réponses: 8
    Dernier message: 16/08/2007, 13h42
  2. Pb avec "BIG ENDIAN"
    Par pdgnr dans le forum Delphi
    Réponses: 2
    Dernier message: 04/09/2006, 09h37
  3. Big endian et Little endian?
    Par moon93 dans le forum C
    Réponses: 4
    Dernier message: 07/05/2006, 22h48
  4. Cast et little/big endian
    Par progfou dans le forum C
    Réponses: 8
    Dernier message: 29/03/2006, 18h54
  5. Comment écrire en big endian dans un fichier ?
    Par j3d dans le forum VB 6 et antérieur
    Réponses: 11
    Dernier message: 24/07/2005, 21h50

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo