473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Sockets with multiple servers

Hi all,

I am writing an application that is acting as
an web client, that needs to connect to
multiple servers. The web servers are small
embedded web servers that talk to a host
of other electronics. I need my app to
pole each web server to check for changes.

I can connect to the two device I have currently,
first one then the other.

However, if I then attempt to connect to the first
web server again it fails!

This is my code to connect to the server

Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnConnect.Click
m_Client.Close()
m_Client = Nothing

m_Client = New TcpClient(IP_Addr, PORT_NUM)
If m_Client.GetStream.CanRead = False Then
Debug.WriteLine("Can't read from stream")
Else
Debug.WriteLine("Can read from stream")
End If

m_Client.GetStream.BeginRead(m_ReadBuffer, 0,
READ_BUFFER_SIZE, AddressOf DoRead, Nothing)
End Sub

When the connection is remade no data is sent back to
DoRead and the connection is not made.
DoRead is used as a asynchronous reader for the stream.

Private Sub DoRead(ByVal ar As IAsyncResult)
Dim bytesRead As Integer
Dim message As String

Try
bytesRead = m_Client.GetStream.EndRead(ar)
If bytesRead < 1 Then
Debug.WriteLine("No bytes received on doRead")
Debug.Flush()
Else
message = Encoding.ASCII.GetString(m_ReadBuffer, 0,
bytesRead - 2)
ProcessCommands(message)
End If
' Start a new asynchronous read into readBuffer.
m_Client.GetStream.BeginRead(m_ReadBuffer, 0,
READ_BUFFER_SIZE, AddressOf DoRead, Nothing)
Catch ex As SocketException
MessageBox.Show("DoRead: " & ex.Message &
ControlChars.CrLf & ex.ErrorCode)
Catch ex As Exception
MessageBox.Show("DoRear: " & ex.Message)
End Try
End Sub
Any help with why this is not working, or suggestions
as to how I can connect and disconnect as a tcpClient would
be most appreciated.

Many thanks,

Jason.
Nov 21 '05 #1
0 899

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Virgil Green | last post by:
An associate has asked me to take a look a problem he's having with starting mysql. I thought I'd give it a shot to learn some more about mySQL before having him turn it over to someone more...
10
by: Cory Nelson | last post by:
I've created a new C++ sockets library - small, cross-platform, IPv4 and IPv6. If anyone would like to critique it, I'd appreciate it. Doesn't support the more exotic protocols - only TCP and UDP....
4
by: Dave Edwards | last post by:
I understand that I can fill a datagrid with multiple queries, but I cannot figure out how to fill a dataset with the same query but run against multiple SQL servers, the query , table structure...
5
by: Jason L James | last post by:
Hi all, as a VB.Net programmer I am finding it difficult to find a text on implementing sockets to communicate with an embedded web server. Does anyone know of a good resource, either text...
2
by: Ronodev.Sen | last post by:
the way my program needs to go is -- 1) open a socket and listen on it 2) moment a client connects to the socket - process some data (by sending it to another machine), get the result and send...
2
by: jasonsgeiger | last post by:
From: "Factor" <jasonsgeiger@gmail.com> Newsgroups: microsoft.public.in.csharp Subject: Multiple Clients, One port Date: Wed, 19 Apr 2006 09:36:02 -0700 I'm been working with sockets for a...
35
by: keerthyragavendran | last post by:
hi i'm downloading a single file using multiple threads... how can i specify a particular range of bytes alone from a single large file... for example say if i need only bytes ranging from...
4
by: zaferaydin | last post by:
Hi, i have a Socket based application that works well. The application connects remote servers and getting data from them. When i try to read data from 20-30 servers at the same time, i...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.