Solved

IP communication / sockets

Posted on 2006-06-23
5
226 Views
Last Modified: 2013-11-13
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!
0
Comment
Question by:bernie1774
  • 3
  • 2
5 Comments
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16975451

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

0
 

Author Comment

by:bernie1774
ID: 16976559
is there another way to get to that dialot other then CTRL + T, it dosnt work in visual studio 2005
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16978365

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
0
 

Author Comment

by:bernie1774
ID: 16979808
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
0
 
LVL 13

Accepted Solution

by:
Mark_FreeSoftware earned 500 total points
ID: 16979847

that is indeed an error,
"vbKeyReturn" is a keycode constant,

try vbCRLF, vbCR or vbLF instead

vbCRLF = Chr(13) & chr(10)
vbCR = Chr(13)
vbLF = chr(10)

0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This video teaches viewers about errors in exception handling.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now