-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket_client.py
More file actions
43 lines (33 loc) · 1.06 KB
/
Copy pathsocket_client.py
File metadata and controls
43 lines (33 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
Minimal socket client: connect, send 0100, receive 0110.
Requires a server running (e.g. from test_socket_e2e or a custom handler).
"""
from iso8583_toolkit import build, parse
from iso8583_toolkit.framing import FramingConfig
from iso8583_toolkit.socket_client import Iso8583Client
def main() -> None:
host = "127.0.0.1"
port = 9999 # Change to your server port
req_de = {
2: "1234567890123456",
3: "000000",
4: "000000001000",
11: "000001",
12: "123456",
13: "0217",
}
req = build("0100", req_de)
client = Iso8583Client(host=host, port=port, framing_config=FramingConfig(length_bytes=2))
client.connect()
try:
client.send(req.message)
resp = client.send_and_receive(req.message, timeout=5.0)
if resp:
parsed = parse(resp)
print(f"Response MTI: {parsed.mti}, DE 39: {parsed.data_elements.get(39)}")
else:
print("No response (timeout or error)")
finally:
client.disconnect()
if __name__ == "__main__":
main()