Click here to Skip to main content
15,894,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi to all,
I have vb script for accessing instruments (by using of ip address and port number of instrument).when i trying connect the instrument using of window based application it gives error message as:
"Connection with the server failed the following code was returned:No connection could be made because the target machine actively refused it:192.168.1.250:10000".
Any one help me how to solve this error please...
my vb script is
VB
Option Explicit On
Option Strict On
Imports System.Net.Sockets
Public Class Form 1
Inherits System.Windows.Forms.Form
#Region " Windows Code created by Form Designer "
 ublic Sub New()
MyBase.New()
' This call is necessary for Windows Form Designer.
InitializeComponent()
' InitializeComponent() Initialization is added after the call.
End Sub
' The Form overwrites dispose to execute post-processing in the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
' Necessary for Windows Form Designer.
Private components As System.ComponentModel.IContainer
'Memo: The following procedure is necessary for Windows Form Designer.
'Change by using Windows Form Designer.
'Do not use code editor to change.
'Friend WithEvents components As System.ComponentModel.IContainer


Friend WithEvents Start As System.Windows.Forms.Button
Friend WithEvents lstOutput As System.Windows.Forms.ListBox
<system.diagnostics.debuggerstepthrough()>
Private Sub InitializeComponent()
Me.Start() = New System.Windows.Forms.Button
Me.lstOutput = New System.Windows.Forms.ListBox
Me.SuspendLayout()
'
'Start
'
Me.Start.Location = New System.Drawing.Point(16, 16)
Me.Start.Name = "Start"
Me.Start.Size = New System.Drawing.Size(88, 32)
Me.Start.TabIndex = 0
Me.Start.Text = "Start"
'lstOutput
'
Me.lstOutput.ItemHeight = 12
Me.lstOutput.Location = New System.Drawing.Point(16, 64)
Me.lstOutput.Name = "lstOutput"
Me.lstOutput.Size = New System.Drawing.Size(264, 196)
Me.lstOutput.TabIndex = 1
'
'Form 1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
Me.ClientSize = New System.Drawing.Size(296, 273)
Me.Controls.Add(Me.lstOutput)
Me.Controls.Add(Me.Start)
Me.Name = "Form 1"
Me.Text = "Form 1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Start_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start.Click

Dim IpAddress As String
Dim PortNum As Integer
Dim Client As TcpClient
Dim Buffer() As Byte
Dim InBuff(1532) As Byte
Dim TxCommand As String
Dim RxResponse As String
Dim Temp As String
Dim j As Integer
Dim Dreg(5) As Double
Dim DregStr$
Dim SubHeader$
' IP Address specification
IpAddress = "192.168.1.250"
' Port Number specification
PortNum = 10000
Client = New TcpClient
'Line connection processing
Try
Client.Connect(IpAddress, PortNum)
Catch ex As Exception
MsgBox("Connection with the server failed, and the following code was returned:" & ex.Message, 0, "connection error")
Exit Sub
End Try
'Read D0 to D4 (5 points) with the A-compatible 1E frame command.
TxCommand = "01ff000a4420000000000500"
Buffer = System.Text.Encoding.Default.GetBytes(TxCommand.ToCharArray)
'Sending a read command
Client.GetStream().Write(Buffer, 0, Buffer.Length)
'Waiting for a response from an Ethernet adapter
While Not Client.GetStream().DataAvailable()
Application.DoEvents()
End While
If Client.GetStream().DataAvailable() Then
Client.GetStream().Read(InBuff, 0, InBuff.Length)
RxResponse = System.Text.Encoding.Default.GetString(InBuff)
SubHeader = Mid$(RxResponse, 3, 2)
If SubHeader = "00" Then 'Normal response
Temp = "" 'Initialization of an output character string
For j = 0 To 4
DregStr$ = Mid(RxResponse, j * 4 + 5, 4)
Dreg(j) = Val("&H" + DregStr$)
Temp = Temp + Format(Dreg(j), "#####0") + " "
Next
lstOutput.Items.Insert(lstOutput.Items.Count, Temp)
ElseIf SubHeader = "5B" Then ' In an abnormal response, an abnormal code is added.
Temp = "Terminate Code = " & SubHeader & " Error Code = " & Mid$(RxResponse, 5, 2)
lstOutput.Items.Insert(lstOutput.Items.Count, Temp)
Else
Temp = "Terminate Code = " & SubHeader
lstOutput.Items.Insert(lstOutput.Items.Count, Temp)
End If
lstOutput.SelectedIndex = lstOutput.Items.Count - 1
End If
' Line disconnection processing
Client.GetStream().Close()
Client.Close()
End Sub
End Class


[Edit]Code block added[/Edit]
Posted
Updated 1-Nov-12 23:05pm
v2

This is only the client application.
You can't create a connection without a server.
So, you need to create a server and start the server before you start the client.

Here's an article about creating client/server programs:
Building Client/Server applications with VB.NET for secure private file sharing[^]
 
Share this answer
 
v2
ok thanks for your response ...
Actually i am new about vb script can you help me in server program and i have doubt that is can we write the program with client and sever application in single program.
Actually my need is i was create one start button and list box when i pressed the start button 4 values will be displayed in list box from instrument for i followed FX-3U-ENET-ADP user manual document in that i follows window based vb application as mention in appendex:c of document.Can you please refer this document and please give me your suggestions.
 
Share this answer
 
v2
Comments
Thomas Daniels 2-Nov-12 7:23am    
Ok, I updated my answer. I've added a link to an article about creating client/server programs.
chandinig 2-Nov-12 8:13am    
server is not cpu it is hard ware i has default ip address
Thomas Daniels 2-Nov-12 8:47am    
What do you mean exactly?
chandinig 4-Nov-12 23:12pm    
my actual need is i have one hard ware it has some ip address(192.168.1.250).After that i am trying to access the data from hard ware by using of vb script(window based application).But it does not works fine it gives error as "Connection with the server failed the following code was returned:No connection could be made because the target machine actively refused it:192.168.1.250:10000".how to solve this error please help me...
my vb script is:
Option Explicit On
Option Strict On
Imports System.Net.Sockets
Public Class Form 1
Inherits System.Windows.Forms.Form
#Region " Windows Code created by Form Designer "
Public Sub New()
MyBase.New()
' This call is necessary for Windows Form Designer.
InitializeComponent()
' InitializeComponent() Initialization is added after the call.
End Sub
' The Form overwrites dispose to execute post-processing in the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
' Necessary for Windows Form Designer.
Private components As System.ComponentModel.IContainer
'Memo: The following procedure is necessary for Windows Form Designer.
'Change by using Windows Form Designer.
'Do not use code editor to change.
'Friend WithEvents components As System.ComponentModel.IContainer


Friend WithEvents Start As System.Windows.Forms.Button
Friend WithEvents lstOutput As System.Windows.Forms.ListBox
<system.diagnostics.debuggerstepthrough()>
Private Sub InitializeComponent()
Me.Start() = New System.Windows.Forms.Button
Me.lstOutput = New System.Windows.Forms.ListBox
Me.SuspendLayout()
'
'Start
'
Me.Start.Location = New System.Drawing.Point(16, 16)
Me.Start.Name = "Start"
Me.Start.Size = New System.Drawing.Size(88, 32)
Me.Start.TabIndex = 0
Me.Start.Text = "Start"
'lstOutput
'
Me.lstOutput.ItemHeight = 12
Me.lstOutput.Location = New System.Drawing.Point(16, 64)
Me.lstOutput.Name = "lstOutput"
Me.lstOutput.Size = New System.Drawing.Size(264, 196)
Me.lstOutput.TabIndex = 1
'
'Form 1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
Me.ClientSize = New System.Drawing.Size(296, 273)
Me.Controls.Add(Me.lstOutput)
Me.Controls.Add(Me.Start)
Me.Name = "Form 1"
Me.Text = "Form 1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Start_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start.Click

Dim IpAddress As String
Dim PortNum As Integer
Dim Client As TcpClient
Dim Buffer() As Byte
Dim InBuff(1532) As Byte
Dim TxCommand As String
Dim RxResponse As String
Dim Temp As String
Dim j As Integer
Dim Dreg(5) As Double
Dim DregStr$
Dim SubHeader$
' IP Address specification
IpAddress = "192.168.1.250"
' Port Number specification
PortNum = 10000
Client = New TcpClient
'Line connection processing
Try
Client.Connect(IpAddress, PortNum)
Catch ex As Exception
MsgBox("Connection with the server failed, and the following code was returned:" & ex.Message, 0, "connection error")
Exit Sub
End Try
'Read D0 to D4 (5 points) with the A-compatible 1E frame command.
TxCommand = "01ff000a4420000000000500"
Buffer = System.Text.Encoding.Default.GetBytes(TxCommand.ToCharArray)
'Sending a read command
Client.GetStream().Write(Buffer, 0, Buffer.Length)
'Waiting for a response from an Ethernet adapter
While Not Client.GetStream().DataAvailable()
Application.DoEvents()
End While
If Client.GetStream().DataAvailable() Then
Client.GetStream().Read(InBuff, 0, InBuff.Length)
RxResponse = System.Text.Encoding.Default.GetString(InBuff)
SubHeader = Mid$(RxResponse, 3, 2)
If SubHeader = "00" Then 'Normal response
Temp = "" 'Initialization of an output character string
For j = 0 To 4
DregStr$ = Mid(RxResponse, j * 4 + 5, 4)
Dreg(j) = Val("&H" + DregStr$)
Temp = Temp + Format(Dreg(j), "#####0") + " "
Next
lstOutput.Items.Insert(lstOutput.Items.Count, Temp)
ElseIf SubHeader = "5B" Then ' In an abnormal response, an abnormal code is added.
Temp = "Terminate Code = " & SubH
Akinmade Bond 3-Nov-12 10:11am    
:\

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900