UDP kommunikation volder problemer.
PROGRAMMERINGSVÆRKTØJ: Microsoft Visual Basic 2005 Express EditionTESTPROGRAM: Jeg har et ældre kompileret VB6 program der virker, dvs. jeg kan teste at forbindelse og kommunikation mellem PC og HOST/IC virker. Hardware er altså OK.
STATUS: Jeg har 2 programmer som kaldes NYT PROGRAM (VS 2005)og GAMMELT PROGRAM (VB6), hvilket fremgår at overskrifterne. Det gamle program virker i kompileret kode og jeg forsøger nu at lave tilsvarende kode i Visual Basic 2005 Express Edition. Men jeg kan ikke få koden til at virke.
ADD-IN: Da jeg ikke havde WINSOCKET på min PC, har jeg installeret den efter denne vejledning: http://www.ascentive.com/support/new/support_dll.phtml?dllname=MSWINSCK.OCX
HJÆLP: Hjælp mig med at få min Visual Basic 2005 Express Edition kode til at fungere.
----------- START NYT PROGRAM (VB 2005)---------
Public Class Form1
Dim LPort, Temp, TempString, txtIn, txtOut, tx, ReciveCounttxt As String
Dim RemoteHost_IP, RemoteHost_Port, SendCount, ReciveCount As Integer
Dim FileIsOpen As Integer
Dim a As FileAttribute
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'CONNECT
Shell("route add 10.10.6.100 192.168.2.150")
RemoteHost_IP = "10.10.6.100"
RemoteHost_Port = 1234
LPort = 1004
SendCount = 0
ReciveCount = 0
FileIsOpen = False
sckMain.RemoteHost = RemoteHost_IP
sckMain.RemotePort = RemoteHost_Port
sckMain.LocalPort = LPort
sckMain.Connect()
'sckMain.Bind()
'SEND DATA
Temp = Now
TempString = "XXXX"
txtIn = TempString
sckMain.SendData(txtIn)
SendCount = SendCount + 1
txtOut = ""
'RECIEVE DATA
Dim sText As String
sckMain.GetData(tx)
RemoteHost_IP = sckMain.RemoteHost
RemoteHost_Port = sckMain.RemotePort
txtOut = txtOut & " " & tx
ReciveCount = ReciveCount + 1
ReciveCounttxt = ReciveCount
sText = tx
TextBox1.Text = tx
TextBox1.Refresh()
'DISCONNECT
sckMain.Close()
End Sub
End Class
----------- SLUT NYT PROGRAM (VS 2005)----------
----------- START GAMMELT PROGRAM (VB6)---------
Dim SendCount As Integer
Dim ReciveCount As Integer
Dim TempString As String
Dim Temp As String
Dim sFileName As String
Dim FileIsOpen As Integer
Dim a As Integer
Dim RemoteHost_IP As String
Dim RemoteHost_Port As String
Private Sub cmdConnect_Click()
Shell ("route add 10.10.6.100 80.196.240.149")
sckMain.RemoteHost = txtRHost
RemoteHost_IP = txtRHost
sckMain.RemotePort = txtRPort
RemoteHost_Port = txtRPort
sckMain.Bind txtLPort
SendCount = 0
ReciveCount = 0
FileIsOpen = False
End Sub
Private Sub cmdSend_Click()
Temp = Now
TempString = "XXXX"
txtIn = TempString
sckMain.RemoteHost = RemoteHost_IP
sckMain.RemotePort = RemoteHost_Port
sckMain.SendData txtIn.Text
SendCount = SendCount + 1
SendCountTxt.Text = SendCount
txtOut.Text = ""
End Sub
Private Sub Disconnect_Click()
sckMain.Close
Close #a
End Sub
Private Sub sckMain_Dataarrival(ByVal bytesTotal As Long)
Dim sText As String
Dim tx$
If FileIsOpen = False Then
a = FreeFile
Open ("C:/LogData.txt") For Output As #a
FileIsOpen = True
Print #a, "Logfil fra VB_6"
End If
sckMain.GetData tx$
RemoteHost_IP = sckMain.RemoteHost
RemoteHost_Port = sckMain.RemotePort
txtOut.Text = txtOut.Text & " " & tx$
ReciveCount = ReciveCount + 1
ReciveCountTxt.Text = ReciveCount
sText = tx$
Print #a, tx$
If sText = "#" Then
'Flush a
Close #a
FileIsOpen = False
txtOut.Text = "Sidste data modtaget! og filen lukkes"
End If
End Sub
----------- SLUT GAMMELT PROGRAM (VB6)---------
