473,396 Members | 1,693 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,396 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 1473

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.