Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Visual basic sockets

Posted on 2003-02-23
6
Medium Priority
?
234 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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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 …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This video teaches viewers about errors in exception handling.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

564 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