473,795 Members | 2,667 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Socket Exception is : The operation is not allowed on non-connected sockets.

2 New Member
Hi all,

i've been having this problem and its kiiling me! i'm a newbie at this so i hope someone would be able to help me.

picture link: http://i98.photobucket.com/albums/l2...plication2.jpg

this pops up whenever i click on the Disconnect button after i have connected.

these are the following codes for the program.
Expand|Select|Wrap|Line Numbers
  1. Imports SN = System.Net
  2. Imports SNS = System.Net.Sockets
  3. Imports ST = System.Text
  4. Imports System.Net
  5.  
  6. Public Class _Default
  7.     Dim tcpClient As New System.Net.Sockets.TcpClient
  8.     Dim connectport As String
  9.  
  10.     Sub dc(ByVal tcpclient As SNS.TcpClient)
  11.         Dim NetworkStream As SNS.NetworkStream = tcpclient.GetStream
  12.         tcpclient.Client.Close()
  13.         NetworkStream.Close()
  14.         msg("Disconnected from port:" + connectport)
  15.         status("IP:" + "Disconnected" + vbCrLf + "Port:" + "Disconnected")
  16.     End Sub
  17.  
  18.     Private Sub dcBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dcBtn.Click
  19.         Try
  20.             dc(tcpClient)
  21.         Catch ex As Exception
  22.             msg("Socket Exception is : " & ex.Message)
  23.         End Try
  24.     End Sub
  25.  
  26. End Class
  27.  
  28. Partial Class _Default
  29.     Inherits System.Web.UI.Page
  30.  
  31.     Sub msg(ByVal message As String)
  32.         Msgbox.Text = Msgbox.Text + message + vbCrLf
  33.     End Sub
  34.  
  35.     Sub status(ByVal message As String)
  36.         statusbox.Text = message + vbCrLf
  37.     End Sub
  38.     Sub outputconnect(ByVal tcpclient As SNS.TcpClient)
  39.         'Input IP Address and TCP port
  40.         Dim address As String
  41.         Dim port As String
  42.         address = ipbox.Text
  43.         port = portbox.Text
  44.         connectport = portbox.Text
  45.  
  46.         If tcpclient.Connected = False Then
  47.             tcpclient.Connect(address, port)
  48.             msg("Connected to IP:" + address + " via port:" + port)
  49.             status("IP:" + address + vbCrLf + "Port:" + port)
  50.         End If
  51.     End Sub
  52.  
  53.  
  54.     Private Sub connectBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles connectBtn.Click
  55.         tcpClient = New System.Net.Sockets.TcpClient
  56.         Try
  57.             outputconnect(tcpClient)
  58.         Catch ex As Exception
  59.             msg("Socket Exception is : " & ex.Message)
  60.         End Try
  61.     End Sub
  62. End Class

I hope someone would be able to help me, i would really appreciate it!

Keith.
Oct 23 '09 #1
4 15306
dafodil
392 Contributor
The exception clearly states that you should not try to disconnect unconnected sockets. Instead of declaring new sockets to disconnect, I suggest try to use you're old TcpClient connection.
Oct 23 '09 #2
Frinavale
9,735 Recognized Expert Moderator Expert
Check if the TcpClient is closed before attempting to use it.
Oct 27 '09 #3
keithseah
2 New Member
How do i check if my TcpClient is closed or how do i use my old TcpClient?
Sorry i'm really new at this so i dont even know the basics.
Oct 28 '09 #4
Frinavale
9,735 Recognized Expert Moderator Expert
Use the TcpClient.Conne cted property to check whether the underlying Socket for the TcpClient is connected to a remote host.

Cheers!

-Frinny
Oct 28 '09 #5

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

Similar topics

2
3092
by: David Konerding | last post by:
Hello, I have written an app which opens a TCP connection to a server and uses a protocol to communicate with it. Specifically, I've written a python IMD client for the molecular dynamics application 'NAMD' (do searches for IMD and NAMD if you want to learn more). The protocol is very simple: both ends of the TCP connection can send messages to the other side at any time; when data is available on a read socket, a full packet (with known...
2
5217
by: Piotr Bieniek | last post by:
Hello, I have a problem with UDP sockets. It concerns UdpClient class as well. It throws strange exceptions on subsequent Send calls. Exception is SocketException with native error code 10049. I noticed that it happens when I call Send for the second time in my program. It seemed strange, so I compiled and run Chat sample program from MSDN. To my surprise, it worked. But then I modified it. The only change was that I duplicated sending...
0
1005
by: Todd Bandrowsky | last post by:
Any idea why a web service synchronously called would throw a socket exception some time ten minutes down the road?
1
321
by: mp | last post by:
Hi, I have following problem: Operation must use an updateable query I have use OleDb, C# and ASP.NET and MS Access DB named pubs. Code:
2
1680
by: Naveen Mukkelli | last post by:
Hi, I'm writing a client/server app. I want to run my server on "Windows Server 2003" PC. This PC has two network cards. 1 for Internet and other is plugged into a switch. My plan is that I'll connect 2 or 4 PC to the switch and the server PC will give out DHCP IP address.
1
10702
by: Bernd | last post by:
Hello, i have a problem with my network code. What i want to do is, send an UDP-packet and check if i get an icmp-reply type 3 (dest. unreachable). the code looks like that so far: .. ..
6
4252
by: Rik | last post by:
Hello Experts, I have a communication server in VB.NET. It was working fine from last 6 months, but now start giving error message like that. 21-03-2005 07:58:27 DoListenSystem.Net.Sockets.SocketException: A blocking operation was interrupted by a call to WSACancelBlockingCall at System.Net.Sockets.Socket.Accept() at System.Net.Sockets.TcpListener.AcceptTcpClient() at ProjectCommServer.CommServer.DoListen()
4
24187
by: Rollasoc | last post by:
Hi, We have a range of four products that can talk to our software (Written in C# & managed C++) via ethernet. Using standard socket class. This has all been working fine for a long time now, under DotNet 1.1. We have now converted the project to DotNet 2.0 Unfortunetely, the code no longer works for one of the products. The
6
1845
by: toton | last post by:
Hi, I am c++ standard exceptions like out_of_range, but want it to have some nonascii message. However what returns a char* and the class is not templated. Do I need to write my own exception class for this purpose? Same problem I am facing with fstream. The open function is non-templated and takes a char* as file name. The file is always ascii, thus no wstream is needed, but the file-name sometime contains non-ascii character.
2
2706
by: Steve Walton | last post by:
We have a little server application that sends data down to a client application via a TCP/IP socket over port 30006. These applications are both written in C#. They have been working on our site for a couple of years. Now, we are trying to use these applications at another site and we get an exception on the following line:- Socket oRequest = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); The exception...
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10213
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10163
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7538
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5436
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.