Ben Drury
Ben Drury

Reputation: 1376

send Iso8583 Message via socket in c#

I am trying to send an Iso8583 message via socket, but that code I've used seems to just hang!

string NewISOmsg = iso8583.Build(DE, MTI);

// Send Message
byte[] data = new byte[1024];
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("66.147.172.198"), 6181);
Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
data = Encoding.ASCII.GetBytes(NewISOmsg);
server.SendTo(data, data.Length, SocketFlags.None, ipep);
IPEndPoint theSender = new IPEndPoint(IPAddress.Parse("66.147.172.198"), 6181);
EndPoint tmpRemote = (EndPoint)theSender;
int recv = server.ReceiveFrom(data, ref tmpRemote);
string ourResponse = tmpRemote.ToString();
server.Close();               

// Output response
Response.Write(ourResponse);                

What am I missing? Thanks, Ben

Upvotes: 0

Views: 2652

Answers (1)

lboshuizen
lboshuizen

Reputation: 2786

To me it seems that you open 2 connections to same end-point,

One to write and a new one to read, basically starting 2 sessions.

The endpoint tries to send back a response on the first connection, so you should read from the first and not from the new second connection.

Upvotes: 2

Related Questions