Solved

IP communication / sockets

Posted on 2006-06-23
5
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

623 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