472,805 Members | 4,092 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

sending over asynchronous socket connect and disconnect

11
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 #1
13 7246
Plater
7,872 Expert 4TB
Are you using UDP, why are you using BeginConnect and all that business?
Oct 16 '07 #2
trymore
11
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."


anybody please help me. i am stuck
Oct 16 '07 #3
trymore
11
is there any other way around it besides using beginconnect? please help
Oct 16 '07 #4
trymore
11
by the way i am using multithreading also. i have ten threads each has its own beginconnect and send subs
Oct 16 '07 #5
Plater
7,872 Expert 4TB
Shouldn't there be a "server" just listening for connections?
Then your "client" makes a socket, connects, sends data, gets reply, disconnects, closes and disposes of the socket.
????
Oct 16 '07 #6
trymore
11
the server that i am sending to i have no control of how it should recieve my data. It will only take one tran then dissconnects and wait for a connect request again until i push all the transactions
Oct 16 '07 #7
Plater
7,872 Expert 4TB
that sounds fine. so just do the client part
Oct 16 '07 #8
trymore
11
any suggestions guys to the error i am getting?
Oct 17 '07 #9
Plater
7,872 Expert 4TB
Yes, don't use the same socket object in all of your threads.
Give each thread their own socket.
Oct 17 '07 #10
trymore
11
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
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.Connected = False Then
client1.BeginConnect(remoteEP, New AsyncCallback(AddressOf Async.ConnectCallback1), client1)
End If
'System.Threading.Thread.Sleep(3000) ' pause for three secs to allow recieving of ENQ

' Wait for connection.
Async.connectDone.WaitOne()
'If ReceiveENQ(client) = "05" Then

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

Async.Receive1(client1) ' recieve ack
System.Threading.Thread.Sleep(2000)
'receiveDone.WaitOne()
Async.Send1(client1, Sringer1)
Async.sendDone.WaitOne()
'System.Threading.Thread.Sleep(5000)
' client1.Close()
'System.Threading.Thread.Sleep(2000)
' Write the response to the console.
client1.Disconnect(True)
Catch e As Exception
Console.WriteLine(e.Message)
Console.WriteLine("error in the sending region of code ")

Finally
r += 1

End Try
Oct 17 '07 #12
trymore
11
its solved now. cheers,
Oct 19 '07 #13
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(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

Try
Do While (i < Reboot.Length)
j = Reboot.IndexOfAny(reserved, i)
If (j = -1) Then
UrlEncoded.Append(HttpUtility.UrlEncode(Reboot.Sub string(i, (Reboot.Length - i))))
Exit Do
End If
UrlEncoded.Append(HttpUtility.UrlEncode(Reboot.Sub string(i, (j - i))))
UrlEncoded.Append(Reboot.Substring(j, 1))
i = (j + 1)
Loop
SomeBytes = Encoding.UTF8.GetBytes(UrlEncoded.ToString)
Dim ep As New IPEndPoint(IPAddress.Parse(net & "." & ipcounterstart), Convert.ToInt16(startport))
socket.Connect(ep)
socket.SendTo(SomeBytes, ep)
Dim cnt As Integer = 0
Dim bytBuffer As Byte() = New Byte(&H400 - 1) {}
Do
cnt = socket.Receive(bytBuffer)
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 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
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...
1
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...
6
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...
4
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...
1
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...
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...
11
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...
2
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...
0
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 ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.