Socket programming trouble
Hi everyone, i'm trying to do a client/server app. I have one trouble: when i send a message to server, i want to receive its answer inmediately. But also, i need to keep socket listening for another messages server can send to client without client sending a message first. That means that in a process i have this code:
Code:
Method()
MainSocket.Send() 'Send data
MainSocket.Receive() 'Receive server answer inmediately
...
End Method
MethodInAnotherProcess()
MainSocket.Receive() 'Block process until new data has arrived
...
End MethodInAnotherProcess
So, when i do that, it throws a SocketException. I guess that i can't call Socket.Receive method when it has called already in another process. So, how can i do that? do i need to use two sockets? one for one task i require and another one for other task?. I would be really apreciated if you can help me guys. Thanks!.
Regards.
Re: Socket programming trouble
I finally could solve it, it's for sure not an elegant solution, but it works fine. I eliminate sub process for receiving data. Instead of it, i create timer. On timer elapsed event, i check socket's available property, if it returns a number wich is bigger than 0, then i start a process to receive data. So in method i use to send and receive data inmediately, i just have to set enabled property to false at beginning of it and set it to true once i had received data. So, Socket's receive method is not called twice. If anybody has another idea, i'd be really greateful if you tell me. Thanks guys!.