Solved

IP communication / sockets

Posted on 2006-06-23
5
239 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Using "ScreenUpdating" 6 55
Problem to start Neon 20 85
recursion example 16 111
MsgBox 4 45
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

911 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