473,387 Members | 1,569 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,387 software developers and data experts.

Socket Connection

Hi Guys

I've created a program in c# that reads data from different port at the same time - so far it was ok connection to 5 ports at the same time using sockets. My concern now is if the administrator from one of the ports "KILL" or "TERMINATE" that particular port my program doesn't catch it. I'm using socketexcetopn as my CATCH and at the same time ObjectDisposedException still no luck. If you run NETSTAT from "cmd" you can see that the connection is "CLOSE_WAIT". What happen is that the connection will always be there. My program is running on 24hrs everyday
I need to monitor that becuase if it's disconnected I need to reconnect it again

CODE

socketList[arrcnt] = new Socket(AddressFamily.InterNetwork,SocketType.Strea m ,ProtocolType.Tcp )
IPAddress ip = IPAddress.Parse (stripd)
Int32 iPortNo = System.Convert.ToInt32 ( strport)
IPEndPoint ipEnd = new IPEndPoint(ip.Address, iPortNo)
socketList[arrcnt].Connect (ipEnd)
WaitForData(socketList[arrcnt])

CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState
tr

//end receive..
int iRx = 0
iRx = theSockId.thisSocket.EndReceive (asyn)
if (theSockId.dataBuffer == null

int sam = System.Environment.TickCount
char[] chars = new char[iRx]; // + 1]
System.Text.Decoder d = System.Text.Encoding.ASCII.GetDecoder()
int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0)
StringBuilder szData = new StringBuilder()
szData.Append(chars)
WaitForData(theSockId.thisSocket)

catch (ObjectDisposedException
{
catch(SocketException se
{System.Diagnostics.EventLog.WriteEntry("ossrop on datareceived",theSockId.thisSocket.RemoteEndPoint. ToString() + " " + se.Message)
Any help or explanation will do. Thanks in advance
/dabuskol
Nov 16 '05 #1
0 1472

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

Similar topics

0
by: Hameed Khan | last post by:
hi all, i am getting some problems with my first socket script. can any one of you point me why this is happening. the server script suppose to accept one connection at a time and send countdown...
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
2
by: Droopy | last post by:
Hi, I try to implement a reusable socket class to send and receive data. It seems to work but I have 2 problems : 1) I rely on Socket.Available to detect that the connection is closed (no...
2
by: Rene Sørensen | last post by:
We are 4 students working on a assignment, that our teacher gave use, normally we do this is C++, but the 4 of us, use C# more often that C++ so… We made a small games called reversi, now our job...
2
by: Nuno Magalhaes | last post by:
I've got a simple problem I guess. How do I know when a connection is terminated without losing any data? I do something like the code below, but sometimes between socket.Receive and socket.Send...
4
by: Engineerik | last post by:
I am trying to create a socket server which will listen for connections from multiple clients and call subroutines in a Fortran DLL and pass the results back to the client. The asynchronous socket...
0
by: palmem | last post by:
I am trying to write a simple FTP server in order to learn about sockets This is my first time trying sockets This code should take a connection on port 8110, dump it to a client "thread" (not...
5
by: darthghandi | last post by:
I've created a class to listen to all interfaces and do a BeginAccept(). Once it gets a connection, it passes the connected socket off and stores it in a List. Next, it continues to listen for...
0
by: Mangabasi | last post by:
Howdy, I would like to use the Synthesis Toolkit for a demo. I downloaded the STK from http://ccrma.stanford.edu/software/stk/index.html. It seems very powerful and user friendly. There are...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.