Another question, this time about sockets

A

Anthony P.

Hello Everyone,

I'm sorry for asking so many questions here but I'm a bit new to web
programming in VB and am having a bit of trouble figuring out even the
simple stuff. Thank you all who have been so gracious as to take your
time to reply to my questions.

So here's what's new:

I have some socket code here: http://pastebin.com/d7d5dc566

This code is an exact copy of a sample that was published on the net
and, apparently, runs for most people. However, when I cut and copy
the code into my VB.NET application, it errors out. The moment I type
something in the client (which is just a telnet window connected to
the port) I get a messagebox saying that "The length cannot be less
than zero" and pointing to the highlighted line in the code at the
link.

I've been working with this code for a while now. I'm really at my
wits end and have no idea how to fix it. Can anyone point me in the
right direction? All I want to do is accept a socket connection and
handle it gracefully. After that, I'll jump into the threading aspects
of it.

Thank you in advance,
Anthony Papillion
 
A

Armin Zingler

Anthony said:
I've been working with this code for a while now. I'm really at my
wits end and have no idea how to fix it. Can anyone point me in the
right direction? All I want to do is accept a socket connection and
handle it gracefully. After that, I'll jump into the threading aspects
of it.


There is no "$" in the received string. Therefore, IndexOf returns -1, which
is not allowed to pass to the SubString method. Insert "debug.print
dataFromClient" before the line throwing the error. You will have to collect
the data from the stream and don't use SubString before IndexOf is > -1.


Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top