views:

51

answers:

2

I am new to Async Socket Connection. Can you please explain. How does this technology work. There's an existing application (server) which requires socket connections to transmit data back and forward. I already create my application (.NET) but the Server application doesn't seem to understand the XML data that I am sending. My documentation is giving me two ports one to Send and another one to Receive. I need to be sure that I understand how this works. I got the IP addresses and also the two Ports to be used.

+1  A: 

A socket is the most "raw" way you can use to send byte-level TCP and UDP packets across a network.

For example, your browser uses a socket TCP connection to connect to the StackOverflow web server on port 80. Your browser and the server exchange commands and data according to an agreed-on structure/protocol (in this case, HTTP). An asynchronous socket is no different than a synchronous socket except that is does not block the thread that's using it.

This is really not the most ideal way to work (check and see if your server/vendor application supports SOAP/Web Services, etc), but if this is really the only way, there could be a number of reasons why it's failing. To name a few...

  1. Not actually getting connected or sending data. Run a test using WinsockTool (http://www.isatools.org/tools/winsocktool.msi) and simulate your client first to make sure the server is working as expected.
  2. Encoding incorrect - You're sending raw bytes across the network... Make sure you're using the correct encoding to convert your XML into bytes (ASCII, UTF8, etc).
  3. Buffer Length - Your sending buffer (the amount of data you can transmit in one shot) may be too small or the server may expect a content of a certain length, and your XML could be getting truncated.
routeNpingme
Thanks for your input; pretty helpful. Unfortunately the vendor/server application doesn't support webservices or SOAP yet. So this is the only way. And to be honest it's kind of painful to make it work. I know for sure that I am connection to the other application. Since a log file exist and is being updated each time that my connection fails. I'll send the ouptut so you can see it.
Tony
: got incoming connection.: accepted, socket = 138485632, 1 connections active.: got traffic on client connection 0, socket = 138485632.: <- [Second Message sent to the serverrrr ] on [138485632]: rc of doRead [1]: doExecute - message received: : unknown message !!: rc of doExecute [1]: connection 0 removed, 0 connections active.
Tony
This is what I get when I try to send info from my app into the server/vendor app174006.115 : got incoming connection.174006.115 : accepted, socket = 58958760, 1 connections active.174006.131 : got traffic on client connection 0, socket = 58958760.174006.131 : rc of doRead [0]174036.319 : had timeout.174036.319 : timeout for msg [], connection 0, socket = 58958760.174036.334 : connection 0 removed, 0 connections active.174608.868 : got incoming connection.174608.883 : accepted, socket = 58958760, 1 connections active.174608.883 : got traffic on client connection 0, socket = 58958760.
Tony
+1  A: 

let's break a misconception... sockets are FULL-DUPLEX: you connect to a server using one port, then you can send AND receive data through the same socket, no need for 2 port numbers. (actually, there is a port assigned for receiving data, but it is: 1. assigned automatically when creating the socket (unless told so) and 2. of no use in the function calls to receive data)

so you tell us that your documentation give you 2 port numbers... i assume that the "server" is an already existing in-house application, and you are trying to talk to it. if the doc lists 2 ports, then you will need 2 sockets: one for sending and another one for receiving. now i would suggest you first use a synchronous socket before trying the async way: a synchronous socket is less error-prone for a first test.

(by the way, let's break another misconception: if well coded, once a server listen on a port, it can receive any number of connection through the same port number, no need to open 2 listening ports to accept 2 connections... sorry for the re-alignment, but i've seen those 2 errors committed enough time, it gives me a urge to kill)

Adrien Plisson
Thanks for you input. Well according to the documentation I have one port for input and another one for output of the application.This is the log being generated when I try to receive data for the other application: got incoming connection.: accepted, socket = 138485632, 1 connections active.: got traffic on client connection 0, socket = 138485632.: <- [Second Message sent to the serverrrr ] on [138485632]: rc of doRead [1]: doExecute - message received: : unknown message !!: rc of doExecute [1]: connection 0 removed, 0 connections active.
Tony