9 Replies - 994 Views - Last Post: 23 March 2010 - 01:40 AM Rate Topic: **--- 2 Votes

#1 Saldash  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 98
  • Joined: 20-December 08

Arrays in VB.Net 2005 Express

Posted 16 March 2010 - 02:43 PM

Hi there,

Does anyone know where I can get some good info in using arrays in VB.Net 2005 Express?

My project is a TCP/IP Server-client setup, with a console based server (on a remote machine)..
sending system information to a form-based app on my machine.

So far I have got the system up and running, but I only know how to send one string of information,
and I want to be able to send any number of different strings to my client application.

If someone knows how I can do this, I would be most grateful :)

OH, also, for some reason, when I close the client the server crashes and I would like to be able to
close and reopen the client without having to restart the server console ;)


Thanks!

P.S. I can upload a copy of the base code for your review, just let me know.

Is This A Good Question/Topic? 0
  • +

Replies To: Arrays in VB.Net 2005 Express

#2 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 1046
  • View blog
  • Posts: 4,072
  • Joined: 02-July 08

Re: Arrays in VB.Net 2005 Express

Posted 16 March 2010 - 04:30 PM

Look in the tutorial section for PCP chat - it should help you out.
Was This Post Helpful? 0
  • +
  • -

#3 Saldash  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 98
  • Joined: 20-December 08

Re: Arrays in VB.Net 2005 Express

Posted 17 March 2010 - 12:56 AM

View Posthawkvalley1, on 16 March 2010 - 10:30 PM, said:

Look in the tutorial section for PCP chat - it should help you out.


I have had a look for this in the VB.Net Tutorials but I cant find any PCP Chat.
I did find one tutorial on arrays but it seemed to be more about creating multiple controls on the form
rather than assigning multiple values.

If you have a link to the tutorial you're referring to that be be very helpful.
(I did do a site search for "PCP Chat" but no results =/ )

Thanks :)

EDIT::
I did find this tutorial -> Arrays
But I'm still unsure whether this will work trying to send the whole array over a network stream.

Let me show you what I have got so far [snippet]:
Dim serverresponse as String = "Server Response" & Convert.ToString(requestcount)
Dim sendbytes as [Byte]() = Encoding.ASCII.GetBytes(serverresponse)
NetworkStream.Write(sendbytes, 0, sendbytes.Length)
NetworkStream.Flush()



Can I use the following in combination with the above like such?:
Dim InfoArray(3) as Integer
InfoArray(1) = "First Info Line"
InfoArray(2) = "Second Info Line"
InfoArray(3) = "Third Info Line"

Dim sendbytes as [Byte]() = Encoding.ASCII.GetBytes(InfoArray)
NetworkStream.Write(sendbytes, 0, sendbytes.Length)
NetworkStream.Flush()



Any input would be great, thanks!

This post has been edited by Saldash: 17 March 2010 - 01:20 AM

Was This Post Helpful? 0
  • +
  • -

#4 Saldash  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 98
  • Joined: 20-December 08

Re: Arrays in VB.Net 2005 Express

Posted 17 March 2010 - 01:45 PM

View PostSaldash, on 17 March 2010 - 06:56 AM, said:

Dim InfoArray(3) as Integer
InfoArray(1) = "First Info Line"
InfoArray(2) = "Second Info Line"
InfoArray(3) = "Third Info Line"

Dim sendbytes as [Byte]() = Encoding.ASCII.GetBytes(InfoArray)
NetworkStream.Write(sendbytes, 0, sendbytes.Length)
NetworkStream.Flush()



I have just tried this, and GetBytes chucks out an error when I try to use a 1-Dimensional array..
Something about not being able to convert it to a string? I thought the array was a string.

(I also tried using Dim InfoArray(3) as String instead of integer, and still the same error)

Any input?
Was This Post Helpful? 0
  • +
  • -

#5 r1zla  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 142
  • Joined: 04-February 10

Re: Arrays in VB.Net 2005 Express

Posted 18 March 2010 - 06:57 AM

There should be two tutorials (unless I'm misunderstanding what you're looking for), one advanced P2P chat tutorial and a simpler version. Both, although using chat as an example, are brilliant for learning how to communicate over a network with vb.net.

First off I'm sure it should be...

Dim InfoArray(3) as String



I think the problem you're having is because you haven't specified a part of the array. For example,

Dim sendbytes as [Byte]() = Encoding.ASCII.GetBytes(InfoArray(1))



Would send the value "First Info Line"

Edit: In my experience arrays are a bit of a pain to work with. You should try using list(of T) instead. They're much more flexible and give you more control. An example of declaring a list would be,
Dim example as list(of string)
:)

This post has been edited by r1zla: 18 March 2010 - 07:03 AM

Was This Post Helpful? 0
  • +
  • -

#6 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 1046
  • View blog
  • Posts: 4,072
  • Joined: 02-July 08

Re: Arrays in VB.Net 2005 Express

Posted 18 March 2010 - 07:51 AM

Yeah I was on my iTouch so I couldn't copy and paste the URL...

Advanced P2P

HTH...
Was This Post Helpful? 0
  • +
  • -

#7 Saldash  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 98
  • Joined: 20-December 08

Re: Arrays in VB.Net 2005 Express

Posted 21 March 2010 - 11:44 AM

Thanks for the replies guys, that has helped me alot :)

I had until now been using a work around, getting the client to send a preset keyword to the server,
which the server reads and send a reply back using an If statement for each keyword.

It was a long work around, and means alot of copy-pasting of the same code over and over...
but I'm now in the process of streamlining using some custom Subs etc..


But anyways.. thanks again for the help!

Now to figure out why the server crashes when I close the client..


/Saldash
Was This Post Helpful? 0
  • +
  • -

#8 r1zla  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 142
  • Joined: 04-February 10

Re: Arrays in VB.Net 2005 Express

Posted 22 March 2010 - 12:21 AM

Are you closing the connection? I can't quite remember but I'm sure if you don;t end it properly then the server tries to maintain a connectiion that isn;t there and crashes. I may be way off base though.
Was This Post Helpful? 0
  • +
  • -

#9 Saldash  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 98
  • Joined: 20-December 08

Re: Arrays in VB.Net 2005 Express

Posted 22 March 2010 - 07:26 AM

View Postr1zla, on 22 March 2010 - 06:21 AM, said:

Are you closing the connection? I can't quite remember but I'm sure if you don;t end it properly then the server tries to maintain a connectiion that isn;t there and crashes. I may be way off base though.


I have setup an exception catch that should end the connection when then client disconnects suddenly, as well as reload the connection ready for the client to connect again,

The problem seems to be that he server is not catching the error or is not closing the exising connection properly and the app ceases up.
I will try to upload my servers source code when I can, but I'm on my iPhone at the moment so that will have to wait unt I'm at home.

Thanks :)
Was This Post Helpful? 0
  • +
  • -

#10 r1zla  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 142
  • Joined: 04-February 10

Re: Arrays in VB.Net 2005 Express

Posted 23 March 2010 - 01:40 AM

Okay, code always helps :) I can't remember but I don;t think I had this problem when i made my chat app a while back. Perhaps I need to peruse over my code again and see if I remember anything.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1