Solved

IP communication / sockets

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to With line 4 74
Math Equation 23 122
VB6 - Cannot type when doing an extract from MSHFlexgrid to Excel 6 34
Help with Classic ASP - Parameterizing Query 14 15
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…
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 …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

735 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