-
I'm trying to transfer data from one winsock to another. I'm getting an error, I don't know why. Here is my code:
Code:
Private Sub Form_Load()
Winsock1.Listen
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Accept
Winsock2.Connect
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Winsock1.GetData clidat, vbString
Text1.Text = Text1.Text & "Client:" & Chr$(13) & Chr$(10) & clidat & Chr$(13) & Chr$(10)
Winsock2.SendData clidat
End Sub
Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
Winsock2.GetData sevdat, vbString
Text1.Text = Text1.Text & "Server:" & Chr$(13) & Chr$(10) & sevdat & Chr$(13) & Chr$(10)
Winsock1.SendData sevdat
End Sub
The protocol is Tcp not Udp. It needs to be TCP. The point of this is to be a log of transfers between a client and server. Any help is appreciated. Please include source, as I'm not too good with winsock.
-
Oh yes, my error occurs when it tried to SendData.
(i.e. Winsock2.SendData clidat)
-
Here is a sample of code I made :
The client
----------
Code:
Private Sub SendData(Message As String)
tcpClient.SendData Message
End Sub
Private Sub tcpClient_DataArrival(ByVal bytesTotal As Long)
tcpClient.GetData StrData
End Sub
Private Sub tcpClient_Close()
tcpClient.Close
End Sub
Private Sub ConnectCommand_Click()
tcpClient.RemoteHost = PostText 'or IP
tcpClient.RemotePort = 1001
If tcpClient.State = sckConnecting Then
ErrorText.Text = "Une demande est en cours ..."
Else: tcpClient.Connect
End If
End Sub
The server :
------------
Private Sub Form_Load()
NumCanal = 0
tcpServer(0).LocalPort = 1001
tcpServer(0).Listen
End Sub
Private Sub tcpServer_ConnectionRequest(index As Integer, ByVal requestID As Long)
If index = 0 Then
NumCanal = NumCanal + 1
Load tcpServer(NumCanal)
tcpServer(NumCanal).LocalPort = 0
tcpServer(NumCanal).Accept requestID
tcpServer(NumCanal).SendData ("Ack")
End If
End Sub
Private Sub tcpServer_DataArrival(index As Integer, ByVal bytesTotal As Long)
Dim Excelapp As Object
Dim StrData As String
Dim toto As String
tcpServer(index).GetData StrData
End Sub
Sorry if there're some text in French because I'm French!
The lacke of your code is the number of the channel. This code allow a multiple-client connection.
[Edited by (B2F)Tom on 07-06-2000 at 07:44 AM]
-
DiGiTaIErRoR
First, the client is not suppose to close a connectin in TCP the is up to the server. That is the protocol requirements.
To allow multiple connections you need to have a control array of winsock controls
Private intMax As Long
Private Sub Form_Load()
intMax = 0
sckServer(0).LocalPort = 1001
sckServer(0).Listen
End Sub
Private Sub sckServer_ConnectionRequest _
(Index As Integer, ByVal requestID As Long)
If Index = 0 Then
intMax = intMax + 1
Load sckServer(intMax)
sckServer(intMax).LocalPort = 0 ' the 0 tells the control to choose the next available free port
sckServer(intMax).Accept requestID
Load txtData(intMax)
End If
End Sub
You set the first control to listen. Upon recieving a connection request it, passes the connection to a new control. This control then finishs the connection. The port is then changed. With the multiple ports you can have multiple connections.
Then the rest of the code will go something like this:
server:
The only Connection request should be on the First control:
any one can take the dataArrival, just need to know who it was.
Private Sub tcpServer_DataArrival(index As Integer, ByVal bytesTotal As Long)
tcpServer(index).GetData StrData
End Sub
if this does not help, let me know, i have a full example, at home. Had to do it for a class
[Edited by jtm7699 on 07-06-2000 at 10:21 AM]
-
I don't think you guys know what I'm trying to do. I'm making pretty much what'd you call a packet viewer.
example
Client <-data-> My Program <-data-> Server
Client connects to My Program then My Program Connects to the server.
After that any data sent between them is logged in My Program, then the data is sent as it would if the client connected directly to the server. Then I have a timer to check if the Client is connected to My Program if not is disconnects from the server. like this:
If winsock1.state = 0 then winsock2.close
I'm pretty sure this is right. More problems....
Sometimes when you dis-connect with the client you can't conenct again until you re-start both program, mine and the client. Also when I make it an EXE an automation error occurs. This only happens when it's an exe.
Thanks for any help.