DevOps Cloud (ADM)
Cybersecurity
IT Operations Cloud
Managed COBOL TcpSocket Client Server Communication with sample
There are C# / VB code samples on the MSDN site:
http://msdn.microsoft.com/en-us/library/w89fhyex.aspx
Which show how to use Sockets to enable network communication.
These samples can be used to a write Synchronous Client program and a Synchronous Server Socket Example program.
These communicate which each other synchronously.
This article shows to convert the Microsoft Managed code to Managed Cobol and what the main components are for this to work.
What is a socket.
A socket opens the network connection for the program, allowing data to be read and written over the network. It is important to note that these sockets are software, not hardware.
Please refer to this URL to get a further explanation of the Microsoft .NET Socket Class, URL: http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.aspx
This article focuses around Synchronous communication. There is also a Asynchronous form of communication. All sockets are asynchronous and use a separate thread because of the basic nature of the I/O. But when you just want to receive data from a socket, you can call a receive data method. If the data is not immediately available, then your thread will block. A time out exception will be thrown if you don't receive data within some set time period. At this point, your program can give up or try again. This technique is using sockets synchronously.
Asynchronous. You can poll your sockets for data. If there is no data, it continues. In this case, there is no time out because you won't call read unless there is actually data waiting for you.
Other major components/technologies used:
You will see most of the code is encapsulated in a try catch block, this helps to handle any potential exceptions that may occur, also this avoids having to wait for long response times if the remote connection cannot be contacted, for example if the remote IP address/host name or Port number cannot be reached, the exception can be handled correctly.
More about the C# to COBOL conversion procedure:
As a starting point to look at converting Code from e.g. Visual Basic or C# to Cobol, you could review the following link in our online documentation:
http://documentation.microfocus.com/help/topic/com.microfocus.eclipse.infocenter.visualcobol.vs/GUID-3C495CA9-2B7A-4890-AC64-005545AED543.html
This section gives examples of how code syntax for the different languages.
Also this article on the codeproject website could be helpful to get yourself familiar:
http://www.codeproject.com/Articles/47571/A-Comparison-Of-net-COBOL-Visual-Basic-and-C
Object-oriented (OO) concepts are fundamental to both .NET and the Java Virtual Machine. If you’re considering deploying COBOL applications onto either platform, you’ll need to have a grounding in OO skills to take full advantage of what these platforms can provide.
We have produced a guide (available here) that provides an introduction to OO concepts for procedural COBOL developers. We plan to build upon the material, so your feedback on the existing material and the new topics you’d like added is most welcome.
The aim of this demonstration is to show how COBOL .NET Synchronous Socket Server and Client work. The Socket Client sends a message to the Socket Server which returns the received message back to the Socket Client.
Please see below how to use the provided sample code:
Let's start by looking and referring back to this screenshot:
-Unzip the included attachment,
-open two Visual COBOL or Enterprise Developer Command prompts,
-In the 1st one launch the Socket Server program, (..\SynchronousServerSocket\bin\Debug\SynchronousServerSocket.exe)
-In the 2nd command prompt launch the socket client, (..\SynchronousSocketClient\bin\Debug\SynchronousSocketClient.exe)
-You should see what is depicted in the two screenshots,
Here are the final C# programs converted to COBOL:
.1) Synchronous Server Socket Example public class SynchronousSocketClient { public static void StartClient() { // Connect to a remote device. // Create a TCP/IP socket. // Connect the socket to the remote endpoint. Catch any errors. Console.WriteLine("Socket connected to {0}", // Encode the data string into a byte array. // Send the data through the socket. // Receive the response from the remote device. // Release the socket. } catch (Exception e) {
.2) Synchronous Client Socket Example public class SynchronousSocketClient { public static void StartClient() { // Connect to a remote device. // Create a TCP/IP socket. // Connect the socket to the remote endpoint. Catch any errors. Console.WriteLine("Socket connected to {0}", // Encode the data string into a byte array. // Send the data through the socket. // Receive the response from the remote device. // Release the socket. } catch (Exception e) {
|
.1) Synchronous Server Socket Example data division. StartListening. * // Echo the data back to the client. .
program-id. SynchronousSocketClient as "ConsoleApplication1.SynchronousSocketClient". data division. StartClient.
|
Click here to download the source code:
2465.SynchronousSocketSourceFiles.zip