0

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

Ben Drury
  • 1,356
  • 2
  • 16
  • 34
  • Are you sure the device you are sending to is sending you a reply? Also, it's not a good idea to code like this for protocols over UDP. If the reply gets dropped, your code will wait forever. – David Schwartz Oct 08 '12 at 12:55
  • What do you mean it hangs? as in it stops responding? or nothing comes out at the other end? – kolossus Oct 09 '12 at 00:52

1 Answers1

2

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.

lboshuizen
  • 2,746
  • 17
  • 20
  • Thanks for the help...is there any help sites with examples on how to do it correctly? I'm kind of at the limit of my experience with this one! ;-) – Ben Drury Oct 08 '12 at 14:04
  • @BenDrury I suggest you pick up a good guide on (BSD) sockets programming for your language of choice and probably on concurrent programming as well. – moosaka Oct 09 '12 at 06:54