473,773 Members | 2,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sending over asynchronous socket connect and disconnect

11 New Member
Hi all,

can anybody help me out there? I am developing a client sockect to send transactions form a DB to a server socket. the way i want is to connect, send, recieve , disconnect, connect, send, recieve and disconnect.... like that until all the transactions are uploaded. my problem is when i send, I am shutting down the socket and when i try to connect and send again i get the following error "Once the socket has been disconnected, you can only reconnect again asynchronously, and only to a different EndPoint. BeginConnect must be called on a thread that won't exit until the operation has been completed."
Oct 16 '07
13 7356
trymore
11 New Member
what do you mean creating a socket fopr each connection? do you mean a different endpoint or just a different socket name but connecting to the same EP(IP addr and port)?
i can see we are getting closer bro.
Oct 17 '07 #11
trymore
11 New Member
this is the code i am using. have a look at it. It is in a while loop and r is the looping variable i am using.

Try
If client1.Connect ed = False Then
client1.BeginCo nnect(remoteEP, New AsyncCallback(A ddressOf Async.ConnectCa llback1), client1)
End If
'System.Threadi ng.Thread.Sleep (3000) ' pause for three secs to allow recieving of ENQ

' Wait for connection.
Async.connectDo ne.WaitOne()
'If ReceiveENQ(clie nt) = "05" Then

' Send data to the remote device.
System.Threadin g.Thread.Sleep( 5000) ' pause for three secs to allow recieving of ENQ
Async.Send1(cli ent1, buffer1)
Async.sendDone. WaitOne()
Async.Receive1( client1) ' recieve ack
Async.Receive1( client1) ' recieve resp
System.Threadin g.Thread.Sleep( 3000)
' Receive the response from the remote device.
Async.Send1(cli ent1, Chr(6)) ' send ack
Async.sendDone. WaitOne()
Async.Send1(cli ent1, bufferZone1) ' send CONF REQUEST
Async.sendDone. WaitOne()

Async.Receive1( client1) ' recieve ack
System.Threadin g.Thread.Sleep( 2000)
'receiveDone.Wa itOne()
Async.Send1(cli ent1, Sringer1)
Async.sendDone. WaitOne()
'System.Threadi ng.Thread.Sleep (5000)
' client1.Close()
'System.Threadi ng.Thread.Sleep (2000)
' Write the response to the console.
client1.Disconn ect(True)
Catch e As Exception
Console.WriteLi ne(e.Message)
Console.WriteLi ne("error in the sending region of code ")

Finally
r += 1

End Try
Oct 17 '07 #12
trymore
11 New Member
its solved now. cheers,
Oct 19 '07 #13
Tomtom69
1 New Member
Hi,

I am getting the same error message with below code. What should I modify to get it working?

Private Sub clnt_reboot()
For n = ipcounterstart To ipcounterend
Dim mySocket = New Socket(AddressF amily.InterNetw ork, SocketType.Stre am, ProtocolType.Tc p)

Try
Do While (i < Reboot.Length)
j = Reboot.IndexOfA ny(reserved, i)
If (j = -1) Then
UrlEncoded.Appe nd(HttpUtility. UrlEncode(Reboo t.Substring(i, (Reboot.Length - i))))
Exit Do
End If
UrlEncoded.Appe nd(HttpUtility. UrlEncode(Reboo t.Substring(i, (j - i))))
UrlEncoded.Appe nd(Reboot.Subst ring(j, 1))
i = (j + 1)
Loop
SomeBytes = Encoding.UTF8.G etBytes(UrlEnco ded.ToString)
Dim ep As New IPEndPoint(IPAd dress.Parse(net & "." & ipcounterstart) , Convert.ToInt16 (startport))
socket.Connect( ep)
socket.SendTo(S omeBytes, ep)
Dim cnt As Integer = 0
Dim bytBuffer As Byte() = New Byte(&H400 - 1) {}
Do
cnt = socket.Receive( bytBuffer)
socket.SetSocke tOption(SocketO ptionLevel.Sock et, SocketOptionNam e.ReceiveTimeou t, 30)
Loop While (cnt <> 0)
Catch ex As Exception
MessageBox.Show (ex.Message)
End Try
mySocket.close( )

Next
MessageBox.Show ("Reboot has been send")
ipcounterstart = startoktett
End Sub
Oct 29 '07 #14

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

Similar topics

3
2493
by: Matthew King | last post by:
Hi all I've written a asynchronous socket client class, but i've found that in order to consume it I have to use events, and cannot simply for example SocketClient client = new SocketClient(110, "some.server.com") client.Connect() client.SendData("Hello World") Instead I have to wait for the async method to raise a Connected event, and call client.SendData from there, for complex chains of operations this because a nightmare chain of...
1
6216
by: Niels Johansen | last post by:
Hello, When using the asynchronous read method in the BufferedStream class, , it seems to me that it blocks like the normal synchronous read method. Why is it so? Why does the BufferedStream.BeginRead() not behave similar to the NetworkStream.BeginRead() ?? The following short program illustrates my problem.: using System;
6
4708
by: Silby | last post by:
Having finally got a working asynchronous server up (sends and recieves data fine) i get stuck again. I'm not quite sure how i can safely disconnect the client. It doesnt really matter how initiates the disconnect, both sides should be able to do it. The problem lies in the callback function for reading data, more specifically, at this point: bytesRead = handler.EndReceive(AR) bytesread is an int, handler a socket and AR and...
4
1925
by: carl_bevil | last post by:
I would like to use a single port to connect to a server. I would like to be able to disconnect a socket using this port and then be able to connect again (on the same port) immediately. I know there is a TIME_WAIT value, but I thought I could get around it by using the ResuseAddress option. Here is what the code looks like (C#): Socket connectSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
1
1570
by: DaTurk | last post by:
Hi, Lets see, for arguements sake lets just say that I have a server, which site waiting to receive connections, it then has an array of sockets that are connected to it. It's receiving all of this asynchronously. Now, this is my problem, I have a seperate application that connects to the server and can disconnect any of the sockets connected to it. But, lets just say I have one client connected, and then I attempt to disconnect them...
4
3605
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 client and asynchronous socket server example code provided in the .NET framework developers guide is a great start but I have not dealt with sockets before and I am struggling with something. From what I can tell the sample server code ...
11
8618
by: atlaste | last post by:
Hi, In an attempt to create a full-blown webcrawler I've found myself writing a wrapper around the Socket class in an attempt to make it completely async, supporting timeouts and some scheduling mechanisms. I use a non-blocking approach for this, using the call to 'poll' to support the async mechanism - rather than the 'begin' and 'end' functions. I already found that connecting doesn't set the "isconnected" variable correctly...
2
3435
by: Nicolas Le Gland | last post by:
Hello everyone here. This is my first post in this newsgroup, I hope I won't be to much off-topic. Feel free to redirect me to any better group. I am getting strange timing issues when failing to asynchronously connect sockets on closed or filtered ports, but I'm quite unsure if this is a PHP issue or my misunderstanding, as it seems that socket streams only wrap around <sys/socket.h>.
0
1307
by: cmrhema | last post by:
Hi, We have an asynchronous server socket program, which works fine BUT, when due to some circumstances, I receive null data or blank data, the server goes to infinite loop Here is the code namespace SocketServer { public class StateObject //class created to clear the duplicate records { // Client socket.
0
9621
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
9454
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
10106
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...
0
8937
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7461
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
5355
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...
1
4009
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
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2851
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.