?
Solved

Visual basic sockets

Posted on 2003-02-23
6
Medium Priority
?
231 Views
Last Modified: 2013-11-25
I dont know anything about VB programming, so I apologize in advance if something sounds wrong.

I have a friend that is writting a client in VB, and I am writing the server in java.  We are having a tough time getting the client and server to talk to each other.  For some reason, whenever his client sends text to the server, the server receives weird unicode characters in the streams.

For instance if he sends "Client says hello", the server might receive "(clover symbol)   Client(diamond)   says(clover symbol)   hello".  He tells me he is sending a pure ascii string, so what gives?

This is a piece of the code he is using to connect:
wsck1.LocalPort = Rnd(3000) + 1000
wsck1.Connect wsck1.RemoteHost, wsck1.RemotePort

If someone could post some sample code that would simply connect to a socket on a certain port, and send a line of text and listen for a response - that would be great.

I hope I have provided enough info for someone to help me here.  Thanks a lot for your time.
0
Comment
Question by:lwinkenb
[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
6 Comments
 

Expert Comment

by:RoryR
ID: 8002590
damn, its so easy it herts...

use the winsock component

i recomend using UDP 4 easyness & speed

1 person:

    With Winsock1
        .RemoteHost = ip
        .RemotePort = 2667
    End With

other person:

    With Winsock1
        .RemoteHost = ip
        .Bind 2667
    End With

1 person:

Winsock1.SendData "wow that was hard :-)"

if ive missed nefing out ppl dont hesitate 2 ask :)
0
 
LVL 5

Author Comment

by:lwinkenb
ID: 8004173
Cant use UDP, it must be TCP/IP.

I'm also not sure what you mean by the "1 person:", and then the "other person".  Is one the server and one the client?
0
 

Expert Comment

by:RoryR
ID: 8004670
yup

tcp/ip is slightly more complicated, im going 2 bed, i'll pasted code in sum time
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 

Accepted Solution

by:
EViLWolf earned 400 total points
ID: 8004957
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim strData As String
    Winsock1.GetData strData
    Text1.Text = Text1.Text & strData & vbCrLf
End Sub

(If you didn't define the variable you used to get the data, then that's why. Just define it as a string and it'll work!)
0
 

Expert Comment

by:EViLWolf
ID: 8004962
Also, if you want a random local port, set it to 0.
0
 

Expert Comment

by:EViLWolf
ID: 8019627
To what I said before, you can define it as anything you want, it all depends on what you want to do... in that case, you needed As String... in file transfer, you need As Byte, etc.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.
Suggested Courses

770 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