I am developing in Visual Studio (Visual Basic 2008) for Windows 2003 servers. I am designing an application which must create and maintain a socket connection to a third party IP address and port. Then I need to be able to send a message to this server from a client app, whether it is a web page or a Windows form. The server can be either Web Service, or Windows Service, but I am not clear how to expose an event to let the server know I want to send a socket transmission or that I have received a socket transmission.
I understand that I will want to use BeginReceive and BeginSend events on the socket, but not how to expose these to the client app which will hopefully reside on another machine. I have looked at various samples, including <a href="[[url removed, login to view]<wbr />[url removed, login to view]<wbr />s/library/<wbr />fx6588te.a<wbr />spx]">this<<wbr />/a>, but the code seems to be ALL synchronous or ALL Asynchronous. I want to connect once and not disconnect between my client requests.
I'm not too worried about concurrent requests as this is a very low volume app and the individual message streams will have a token in them that uniquely identifies the stream of the messages. I do, however need to respond to periodic "handshakes" from the vendor at the other end of the socket.
I'm picturing this as a windows or web service with the following events or inputs/outputs:
ClientRequest(Byval sMsg as String) as int
- Accepts a string from a client machine on my network sending a message out to the third party
ClientResponse() as string
- "knows" when the third-party has sent a message and relays it to the calling application
SendMessage - Performs an asynchronous send and leaves the socket open to receive this response or another
MessageReceived - accepts a message from the socket and notifies the client application
allows the send of a logon message to the third party vendor and receipt of their response. This may need to fire off a thread because the vendor may take up to 2 minutes to connect, causing errors with Windows service start
rejoins the thread if necessary, send a logoff message and exit the service