Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TCP Connection VB 2010 for receiving ascii

Status
Not open for further replies.

lexer

Programmer
Jun 13, 2006
432
0
0
VE
Hi
I'm trying to make a program in VB 2010 for receiving calls information from PBX via TCP, I already has a programa in VB 6.0 using Winsock TCPProtocol that receive the calls made and show them in Textbox, this is the VB 6.0 program:


Code:
Private Sub Form_Load()
    'First Close Connection
    Winsock1.Close
    'Winsock Port
    Winsock1.LocalPort = "8881"
    'Listen Connection
    Winsock1.Listen
End Sub
'Data Arrival
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
        Winsock1.GetData Buffer
        'Show Information received
        Text7.Text = Buffer & Text7.Text
End Sub
Private Sub Winsock1_Close()
    'Close Connection
    Winsock1.Close
    Call Form_Load
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    'CLose Socket
    Winsock1.Close
    'Accept Connection
    Winsock1.Accept requestID
End Sub

The calls information that sends the PBX is in Ascii:
2015/07/13 08:50:49,00:00:00,0,226,O,9184,9184,,0,1002018,0,E226,Joe P.,T9006,Line 6.0,0,0,n/a,0,,,,,,,,,U,Joe P.,

I found out that I can use TCP listener in VB 2010 for receiving the ascii information that send the PBX (I dont know if tcp listener is right way to do it), I'm using this code that I got from the web for getting ascii information and show it in textbox for It makes nothing:

Code:
Imports System.Net.Sockets
Imports System.Text
Imports System.Net
Public Class Form1
    Dim portNo As Integer = 8881
    Dim IP As IPAddress = IPAddress.Parse("127.0.0.1")
    Dim listener As New TcpListener(IP, portNo)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        listener.Start()
        Dim tcpClient As TcpClient = listener.AcceptTcpClient()
        Dim ns As NetworkStream = tcpClient.GetStream
        Dim data(tcpClient.ReceiveBufferSize) As Byte
        '---read incoming stream; Read() is a blocking call---
        Dim numBytesRead As Integer = ns.Read(data, 0, CInt(tcpClient.ReceiveBufferSize))
        '---display data received---
        TextBox1.Text = Encoding.ASCII.GetString(data, 0, numBytesRead)
        Console.WriteLine("Received :" & Encoding.ASCII.GetString(data, 0, numBytesRead))
    End Sub
End Class

Please, Any Ideas?





 
I don't know if you've worked this out yet, and I haven't work with the TcpListener, TcpClient, or VB in years - but I have an idea.

Based on what I can see of your code, you are creating a listener that listens on 127.0.0.1:8881. This is I believe were you are having issues.

When you specify the endpoint of the listener, it will listen specifically on that endpoint - in this case the localhost. Your PBX would not be connecting to the localhost interface, so chances are you aren't even getting past the AcceptTcpClient line.

Instead of using [tt]IPAddress.Parse("127.0.0.1")[/tt] you should be using [tt]IPAddress.IPv6Any[/tt] or [tt]IPAddress.Any[/tt]. Those two should allow your listener to accept the incoming connection from an outside source (such as your PBX).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top