tiwariajay
Newcomer
- Joined
- Dec 10, 2003
- Messages
- 2
I have an application (that doesn't support .NET) on which I am using the old Win32 Winsock controls.
I have another application that does support .NET and on which I am using the Socket class and/or TcpClient and TcpListener classes.
My question is: Can I get old Win32 Winsock application to send/read data from/to the .NET application using the Socket class and/or TcpClient and TcpListener classes?
So far I have not been successful no matter who i make the client or the server.
****** code for old win32 winsock app **********
Private Sub Form_Load()
Winsock1.Protocol = sckTCPProtocol
Winsock1.LocalPort = 9100
Winsock1.Listen
End Sub
Private Sub Winsock1_ConnectionRequest _
(ByVal requestID As Long)
' Check if the control State is closed. If not,
' close the connection before accepting the new
' connection.
If Winsock1.State <> sckClosed Then _
Winsock1.Close
' Accept the request with the requestID
' parameter.
Winsock1.Accept requestID
End Sub
Private Sub txtSendData_Change()
Winsock1.SendData txtSendData.Text
End Sub
Private Sub Winsock1_DataArrival _
(ByVal bytesTotal As Long)
Dim strData As String
Winsock1.GetData strData
txtOutput.Text = strData
End Sub
Private Sub Winsock1_Close()
Winsock1.Close
Winsock1.Listen
End Sub
********** code for .NET winsock **********
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
class Client
{
static void Main(string[] args)
{
try
{
TcpClient tcpClient = new TcpClient();
tcpClient.Connect(localIPaddress, 9100);
NetworkStream networkStream = tcpClient.GetStream();
if(networkStream.CanWrite && networkStream.CanRead)
{
// Reads the NetworkStream to a byte buffer.
byte[] bytes = new byte[38];
networkStream.Read(bytes, 0, bytes.Length);
// Returns to the console the data that is received from the host.
string returndata = Encoding.ASCII.GetString(bytes);
Console.Write("This is what the host returned to you: " + returndata.TrimEnd(new char[] {' '}));
Console.ReadLine();
networkStream.Close();
tcpClient.Close();
}
}
catch (Exception e )
{
Console.WriteLine(e.ToString());
}
}
}
I have another application that does support .NET and on which I am using the Socket class and/or TcpClient and TcpListener classes.
My question is: Can I get old Win32 Winsock application to send/read data from/to the .NET application using the Socket class and/or TcpClient and TcpListener classes?
So far I have not been successful no matter who i make the client or the server.
****** code for old win32 winsock app **********
Private Sub Form_Load()
Winsock1.Protocol = sckTCPProtocol
Winsock1.LocalPort = 9100
Winsock1.Listen
End Sub
Private Sub Winsock1_ConnectionRequest _
(ByVal requestID As Long)
' Check if the control State is closed. If not,
' close the connection before accepting the new
' connection.
If Winsock1.State <> sckClosed Then _
Winsock1.Close
' Accept the request with the requestID
' parameter.
Winsock1.Accept requestID
End Sub
Private Sub txtSendData_Change()
Winsock1.SendData txtSendData.Text
End Sub
Private Sub Winsock1_DataArrival _
(ByVal bytesTotal As Long)
Dim strData As String
Winsock1.GetData strData
txtOutput.Text = strData
End Sub
Private Sub Winsock1_Close()
Winsock1.Close
Winsock1.Listen
End Sub
********** code for .NET winsock **********
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
class Client
{
static void Main(string[] args)
{
try
{
TcpClient tcpClient = new TcpClient();
tcpClient.Connect(localIPaddress, 9100);
NetworkStream networkStream = tcpClient.GetStream();
if(networkStream.CanWrite && networkStream.CanRead)
{
// Reads the NetworkStream to a byte buffer.
byte[] bytes = new byte[38];
networkStream.Read(bytes, 0, bytes.Length);
// Returns to the console the data that is received from the host.
string returndata = Encoding.ASCII.GetString(bytes);
Console.Write("This is what the host returned to you: " + returndata.TrimEnd(new char[] {' '}));
Console.ReadLine();
networkStream.Close();
tcpClient.Close();
}
}
catch (Exception e )
{
Console.WriteLine(e.ToString());
}
}
}