473,405 Members | 2,404 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,405 software developers and data experts.

TcpListener

I'm just getting started with a small TCPIP project in VB.Net.

I've written a successful bit of code but I'm trying to make it work like
VB6 did. In VB6 you have a winsock and set it to connect to an IpAddress on
a certain port. The program then sits there waiting for some data to come
in, and an event is triggered, the data is processed and the routine exits
again.

With VB.Net, there doesn't seem to be an event as such. You set the
tcplister to read the data, and the program hangs until something is read.
How can I get it to trigger an event when it receives something?

- Jerry

Nov 21 '05 #1
3 3386

"Jerry Spence1" <je**********@somewhere.com> wrote in message
news:41***********************@ptn-nntp-reader02.plus.net...
I'm just getting started with a small TCPIP project in VB.Net.

I've written a successful bit of code but I'm trying to make it work like
VB6 did. In VB6 you have a winsock and set it to connect to an IpAddress
on
a certain port. The program then sits there waiting for some data to come
in, and an event is triggered, the data is processed and the routine exits
again.

With VB.Net, there doesn't seem to be an event as such. You set the
tcplister to read the data, and the program hangs until something is read.
How can I get it to trigger an event when it receives something?


The TcpListener is a simplified helper class. Using the underlying Socket
class you can do this with

s.BeginAccept( addressOf MyAcceptMethod, nothing)

But the TcpListener doesn't have this for a good reason. There's no point
in having your listener run asynchronously. Just start a worker thread to
run TcpListener.AcceptTcpClient in a loop. Each time it gets a connection
it should pass it off to a background thread and go back to listening.

David
Nov 21 '05 #2
Thanks David.

Ah - I think the next topic I'd better learn is threading then! If it's
running in a loop, doesn't this eat up processor resources? With an event
this isn't so.
-Jerry

"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in
message news:eo**************@TK2MSFTNGP09.phx.gbl...

"Jerry Spence1" <je**********@somewhere.com> wrote in message
news:41***********************@ptn-nntp-reader02.plus.net...
I'm just getting started with a small TCPIP project in VB.Net.

I've written a successful bit of code but I'm trying to make it work like VB6 did. In VB6 you have a winsock and set it to connect to an IpAddress
on
a certain port. The program then sits there waiting for some data to come in, and an event is triggered, the data is processed and the routine exits again.

With VB.Net, there doesn't seem to be an event as such. You set the
tcplister to read the data, and the program hangs until something is read. How can I get it to trigger an event when it receives something?


The TcpListener is a simplified helper class. Using the underlying Socket
class you can do this with

s.BeginAccept( addressOf MyAcceptMethod, nothing)

But the TcpListener doesn't have this for a good reason. There's no point
in having your listener run asynchronously. Just start a worker thread to
run TcpListener.AcceptTcpClient in a loop. Each time it gets a connection
it should pass it off to a background thread and go back to listening.

David

Nov 21 '05 #3

"Jerry Spence1" <je**********@somewhere.com> wrote in message
news:41***********************@ptn-nntp-reader02.plus.net...
Thanks David.

Ah - I think the next topic I'd better learn is threading then! If it's
running in a loop, doesn't this eat up processor resources? With an event
this isn't so.


The AcceptTcpClient method will block the thread until an incoming
connection is made, so no CPU is used.

David
Nov 21 '05 #4

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

Similar topics

1
by: zZ | last post by:
Hi All, I'm building a TCPListener as the server to accept TCPClient connections, using TCPListener.AcceptTcpClient. I'd like to retrieve client's IP after connected, but found no way to do...
2
by: Keith Langer | last post by:
I have a TCPListener which needs to listen on my LAN IP as well as the loopback address. In VS.Net 2002 the TCPListener constructor could accept the port as an argument and it automatically bound...
0
by: ed | last post by:
Just a warning, I'm somewhat new to .Net. I'm working on a small TCP/IP server used to xfer files between machines over a network. Presently I'm using the TcpListener class with the below C++...
1
by: Doug Wyatt | last post by:
So I'll preface this with the fact that I'm a UNIX developer by training and have just recently gotten in to C# development on Windows. I'm basically running in to a problem whereby I suspect...
4
by: Rob White | last post by:
OK, so I have a TcpListener that is waiting for sockets, this piece of code: IPAddress localAddress = Dns.GetHostByName(Dns.GetHostName()).AddressList; IPEndPoint localEP = new...
2
by: Dave Coate | last post by:
Hi, I am working on a client-server app. I can get two applications to talk to each other on the same machine using 127.0.0.1, but as soon as I try it using a computer name or actual IP address...
3
by: Bjørn Eliasen | last post by:
Hi, I have an application running on all pc's in our company. Basically it is a TCPListener awaiting for sockets to connect and on connection performs the required tasks. The app works fine, but...
4
by: Thos | last post by:
I have a TcpListener that gets started from a GUI button event handler: TcpListener listener; listener = new TcpListener(IPAddress.Any, 1234); listener.Start(backLog); As soon as the third...
1
by: Darwin | last post by:
Setting a server to listen on 8080 for incoming connections. Written in VS2005 on a Multi-homed machine. I get the warning: Warning 1 'System.Net.Sockets.TcpListener.TcpListener(int)' is obsolete:...
1
by: secutos | last post by:
When a TcpListener accepts a connection, it returns a TcpClient, which allows you to recieve data. But what about TcpListener.Server.Receive? Does that also allow to receive data in the same way? Or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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.