473,480 Members | 2268 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Sockets between two remote machines

4 New Member
I hope this is simple enough. I have written a very simple little app that runs on a windows 2008 server machine. It simply listens for connections on a specific port. It then accepts any connection to this port and begins processing the data based on the messages. All of this works locally. I.e. when on the same machine using 127.0.0.1.

The problem is that when I test from two remote machines the socket seems to drop (close) on its own. I am not sure if this is a server 2008 config issue or something else. The socket connects to the little app on the server and identifies itself. data is shared between the two connections. But after 10 seconds I do a ping and the socket is closed. (the ping is an internal process of the app, this ping works locally). I need the connection between the two machines to be continuous.

My hunch is this might be a firewall issue but not sure what to look for.

So to summarize - the app, when local, works. Does as expected.
The app when remote, does accept connections, does process the information and does send the initial data back to the client (which is the socket id).
The problem is that i use a time limited Read on the server (10 seconds). when no data is rx in 10 sec I send a ping to the connected PC to see if still alive. It should be. But is not. So it dropped somewhere in that 10 second window.
Apr 5 '13 #1
3 1454
frederm2004
4 New Member
btw: this is vb.net using visual studio 2010. I was just wondering if anyone know of any extra setup on the server side to keep the socket from closing when using the read timeout method.. it appears this method may not be stable and can leave the socket in an unusable state. SO this could be the issue.
Apr 6 '13 #2
frederm2004
4 New Member
here is the code:
Expand|Select|Wrap|Line Numbers
  1. again:
  2.         ns = sck.GetStream
  3.         ns.ReadTimeout = 5000
  4.         ns.InitializeLifetimeService()
  5.  
  6.         Try
  7.             bytesread = ns.Read(readBuffer, 0, 255) <--- when 5 seconds is up this caused an exception.  But socket ns is also now closed because of this on windows 2008 server.  Not on windows 7 home.
  8.             Console.WriteLine("Bytes Read:" & bytesread)
  9.  
  10.  
  11.             If bytesread > 0 Then
  12.                 data = System.Text.Encoding.UTF8.GetString(readBuffer, 0, bytesread)
  13.                 message &= data
  14.                 Do While message.Contains("$")
  15.                     pos = message.IndexOf("$")
  16.                     If pos > -1 Then
  17.                         cmd = Mid(message, 1, pos)
  18.                         message = Mid(message, pos + 2)
  19.                         If ProcessCommand(sck, cmd) = False Then
  20.                             Console.WriteLine("Process Command returned FALSE on Command:" & cmd)
  21.  
  22.                             'If isPrinterSCK Then PrintSckt = Nothing 'no longer a Printer PC connected
  23.                             sck.Close()
  24.                             totalconns -= 1
  25.                             Console.WriteLine("SOCKET HANDLE: " & sck.Client.Handle.ToInt32.ToString & " Has Disconnected" & "  Total Active Sockets[" & totalconns & "]")
  26.                             Exit Sub 'kill thread
  27.                         End If
  28.  
  29.                     End If
  30.                 Loop
  31.             End If
  32.             GoTo again
  33.   Catch ex As Exception
  34.             Dim m As String = ex.Message
  35.  
  36.             'time out occured
  37.             'check ex value here.
  38.             'if timout occured on read on PC Print Client then send PING command to see if connection still open.  If so resume wait.
  39.             ' Console.WriteLine("Exception occured.  PrintSckt Value:" & IsNothing(PrintSckt))
  40.             ' Console.WriteLine("Exception contain TIME:" & m.ToLower.Contains("time"))
  41.  
  42.             If IsNothing(PrintSckt) = False Then
  43.                 '    Console.WriteLine("Value of PrintSckt: " & PrintSckt.Client.Handle.ToString & "  sck: " & sck.Client.Handle.ToString)
  44.  
  45.  
  46.                 If PrintSckt.Client.Handle = sck.Client.Handle And m.ToLower.Contains("time") Then
  47.                     Console.WriteLine("Socket Connection Status:" & sck.Connected)
  48.                     If SendSckMessage(sck, "PING#$") Then
  49.                         ' Console.WriteLine("Ping sent to Printer Client")
  50.                         GoTo again 'are we the Printer PC Connection?  if so we don't die until we are told to.  no time out here.
  51.                     End If
  52.                 Else
  53.                     Console.WriteLine("PING attempt failed to Printer Client")
  54.  
  55.                     If IsNothing(Err) = False Then Console.WriteLine("Unexpexted error[" & Err.Number.ToString & "] :" & Err.GetException.ToString)
  56.                 End If
  57.             End If
  58.  
  59.             If IsNothing(ex) = False Then Console.WriteLine("Application error:" & ex.Message)
  60.  
  61.             totalconns -= 1
  62.             Console.WriteLine("SOCKET HANDLE: " & sck.Client.Handle.ToInt32.ToString & " Has Disconnected via Exception" & "  Total Active Sockets[" & totalconns & "]")
  63.         End Try
  64.  
  65.         If PrintSckt.Client.Handle = sck.Client.Handle Then PrintSckt = Nothing : printsckid = ""
  66.         Try
  67.             sck.Close()
  68.         Catch ex As Exception
  69.  
  70.         End Try
  71.  
Apr 7 '13 #3
frederm2004
4 New Member
Line #7 of the above code is the timed read that is in question. when it times out an exception is thrown. On line 48 we send a ping to the connected PC. To let it know we are still alive. This is where the error occurs. The routine that runs this states the socket is now closed. When I run this same code on a windows 7 box with both client/server on same machine the error never occurs. My thought now is to get rid of the timed read all together and have the client ping to let the server know it is still there. I have my reasons for doing it this way. It appears that the block read will exception out when a socket closes.
Apr 7 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1885
by: hokieghal99 | last post by:
This may not be possible, but I thought I'd ask anyway. Could I get the below code to run on a Python server where other machines would connect to it (say thru the Web) and get details of *their*...
2
6673
by: Shankar | last post by:
Platform: Windows 2000 machine with SP4 I use MSINFO to find system information on the remote machines on our local network. I am able to run MSINFO successfully on other Windows 2000 machines...
0
1110
by: yoda | last post by:
Hello Hackers, I'm developing a large scale distributed service and part of the requirement is that I be able to monitor clients in a very granular way. To this end, I'd like to know if there...
0
1046
by: Mario Rodriguez | last post by:
Hi people, There is a way to find certificates on an remote store using CAPICOM or WSE?
2
6019
by: Don | last post by:
Hello! I am trying to write some code to access performance counters on a remote machine. Ideally, I would like to add a machine to a tree control (like the "Servers" view in the .NET IDE) and...
1
1463
by: Jeremy | last post by:
I have a program that returns a list of processes running on a remote machine. For the most part it works fine, but if the application is a VB6 app it returns an exception: "Feature is not...
7
2475
by: Ike | last post by:
Let's say I have a MySQL 4.12 database, opened to the internet on 111.111.111.111 allowing all incoming and outgoing ports. I have a username and password setup, which CAN connect to this database,...
0
2391
by: ani007 | last post by:
Hi, I need some information on how to run the applications on remote machine. Exactly what i want is , I have site , from which I shud be able to execute my automation scripts residing in...
7
1810
by: indiarocks | last post by:
I need to perform HTTP Posts on a remote machine from a remote machine. Is this possible ? Say for eg. I ssh into a Linux Box B from my script on Linux Box A and I need to do a HTTP GET/Post from...
2
1664
by: sam | last post by:
Hi, I made asp.net website. I send e-mail via asp.net page to receiver but receiver cannot get email. I use smartertool Server SMTP. Sending and receiving to localhost is working. Sending...
0
7054
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
7057
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,...
1
6756
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
7003
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...
1
4798
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...
0
4495
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3008
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
570
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
199
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.