Link to home
Start Free TrialLog in
Avatar of bernie1774
bernie1774

asked on

IP communication / sockets

I’m looking to write a simple app that will act as an emulator for a server that is not yet coded, so that I can test the client devices that will eventually connect to it.

The goal is this.

The client software will connect to the emulator on port 3434 and send either “A” or “B”

The emulator must look at the data that it was sent from the client, and then respond back to the machine that sent it.  So in this case, if the client sent “A”, the emulator would respond back (also on port 3434) to the requesting machine “You sent A”.  Alternatively, the emulator would respond “You sent B” if the client sent a B.

Anybody know how to throw this together real quick?

Thanks!
Avatar of Mark_FreeSoftware
Mark_FreeSoftware
Flag of Netherlands image


add one microsoft winsock control to your form:
press control + T and select Microsoft wisock control from the list

press ok,
and add one to your form (leave the name)


now paste this code,:


Option Explicit

Private Sub Form_Load()
   Winsock1.Bind 3434
   Winsock1.Listen
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
   Winsock1.Close
   Winsock1.Accept requestID
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim tmp As String
Winsock1.GetData tmp
If tmp = "A" Then
   Winsock1.SendData "You sent A"
elseif tmp = "B" then
   Winsock1.SendData "You sent B"
End If
End Sub

Avatar of bernie1774
bernie1774

ASKER

is there another way to get to that dialot other then CTRL + T, it dosnt work in visual studio 2005

right mouse button on your controls panel (at the left side, where you can choose a component)

and then click on components



//the next time, it is better to say if you are using somthing different than vb6
OK, tried that, in VB6 now that I have access to my laptop again, and it runs fine, and listens fine, but when I sent it either of the strings in the IF statement, it dies that the line:

If tmp = "A" + vbKeyReturn Then

with "runtime error 13, type mismatch"




Option Explicit

Private Sub Form_Load()
   Winsock1.Bind 4343
   Winsock1.Listen
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
   Winsock1.Close
   Winsock1.Accept requestID
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim tmp As String
Winsock1.GetData tmp
Text1.Text = tmp
If tmp = "A" + vbKeyReturn Then
   Winsock1.SendData "You sent A"
ElseIf tmp = "B" + vbKeyReturn Then
   Winsock1.SendData "You sent B"
End If
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Mark_FreeSoftware
Mark_FreeSoftware
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial