Click here to Skip to main content
15,897,704 members
Home / Discussions / C#
   

C#

 
Generalusing a dll in my project Pin
Anonymous15-May-05 0:43
Anonymous15-May-05 0:43 
GeneralRe: using a dll in my project Pin
MoustafaS15-May-05 1:37
MoustafaS15-May-05 1:37 
GeneralRe: using a dll in my project Pin
Anonymous15-May-05 1:50
Anonymous15-May-05 1:50 
GeneralRe: using a dll in my project Pin
MoustafaS15-May-05 1:59
MoustafaS15-May-05 1:59 
GeneralRe: using a dll in my project Pin
Anonymous15-May-05 2:05
Anonymous15-May-05 2:05 
GeneralRe: using a dll in my project Pin
Anonymous15-May-05 2:12
Anonymous15-May-05 2:12 
GeneralRe: using a dll in my project Pin
MoustafaS15-May-05 2:16
MoustafaS15-May-05 2:16 
GeneralAsynchronous Client/Server messages Pin
methodincharge14-May-05 23:37
methodincharge14-May-05 23:37 
Yet again I am stuck. I've followed many code examples, most of which are wholly different and do not explain the small details I am lacking in my implementation. Basically what has happened is that, using the Async message sending I have implemented, the messages run together and mix data, which is obviously no good. I assumed that the Async BeginSend took care of this, but I guess I was wrong, either that or I did it wrong. The code below is my basic implementation:

<br />
public void SendMessage(String msg) <br />
			{<br />
				try<br />
				{<br />
					if(m_sndCallBack == null) <br />
					{<br />
						m_sndCallBack = new AsyncCallback(OnDataSent);<br />
					}<br />
					SocketPacket packet = new SocketPacket();<br />
					packet.thisSocket = m_clientSocket;<br />
<br />
					packet.dataBuffer = Encoding.UTF8.GetBytes(msg);<br />
<br />
					m_clientSocket.BeginSend(packet.dataBuffer,<br />
						0, packet.dataBuffer.Length,<br />
						SocketFlags.None, <br />
						m_sndCallBack, <br />
						packet);<br />
				}<br />
				catch(SocketException se)<br />
				{<br />
					Debug.WriteLine(se.Message);<br />
				}	<br />
			}<br />
			public void OnDataSent(IAsyncResult asyn)<br />
			{<br />
				SocketPacket theSockId = (SocketPacket)asyn.AsyncState;<br />
				try<br />
				{<br />
					int iRx  = theSockId.thisSocket.EndSend (asyn);<br />
					theSockId.thisSocket = null;<br />
				}<br />
				catch (ObjectDisposedException )<br />
				{<br />
					Debug.WriteLine("Web.OnDataReceived: Socket has been closed");<br />
				}<br />
				catch(SocketException se)<br />
				{<br />
					Debug.WriteLine("Web.OnDataReceived: "+se.Message);<br />
				}<br />
			}<br />


Now my typical calling, which may be the problem? would be:
ClientServer.SendMessage("CONNECT:username:password");
...
ClientServer.SendMessage("REQUEST:STATUS");
ClientServer.SendMessage("REQUEST:LIST");

and the server receives:
CONNECT:username:passwordREQUEST:STATUS...

Am I supposed to be waiting on the data to be sent? And if so, should I not even implement the sending using Async code? Any help would be greatly appreciated.
GeneralRe: Asynchronous Client/Server messages Pin
S. Senthil Kumar15-May-05 2:53
S. Senthil Kumar15-May-05 2:53 
GeneralRe: Asynchronous Client/Server messages Pin
methodincharge15-May-05 7:13
methodincharge15-May-05 7:13 
GeneralRe: Asynchronous Client/Server messages Pin
S. Senthil Kumar15-May-05 7:25
S. Senthil Kumar15-May-05 7:25 
GeneralRe: Asynchronous Client/Server messages Pin
methodincharge16-May-05 7:34
methodincharge16-May-05 7:34 
GeneralPower Builder Pin
quocbao14-May-05 21:26
quocbao14-May-05 21:26 
GeneralCheck if a user is a member of a local group Pin
Johny Ng14-May-05 19:42
Johny Ng14-May-05 19:42 
Generalc# and DCOM Pin
Millzy14-May-05 10:22
Millzy14-May-05 10:22 
GeneralVoice Over IP Pin
charbelzibara14-May-05 9:20
charbelzibara14-May-05 9:20 
GeneralRe: Voice Over IP Pin
Dave Kreskowiak15-May-05 5:57
mveDave Kreskowiak15-May-05 5:57 
GeneralDateTime Pin
Bahadir Cambel14-May-05 9:15
Bahadir Cambel14-May-05 9:15 
GeneralRe: DateTime Pin
quilkin14-May-05 10:34
quilkin14-May-05 10:34 
GeneralRe: DateTime Pin
Luis Alonso Ramos14-May-05 17:13
Luis Alonso Ramos14-May-05 17:13 
GeneralRe: DateTime Pin
pubududilena15-May-05 18:15
pubududilena15-May-05 18:15 
GeneralNewbie: Q regarding Sorting DataGrid Pin
nad226314-May-05 8:36
nad226314-May-05 8:36 
GeneralRe: Newbie: Q regarding Sorting DataGrid Pin
MoustafaS14-May-05 14:41
MoustafaS14-May-05 14:41 
GeneralRe: Newbie: Q regarding Sorting DataGrid Pin
nad226314-May-05 18:21
nad226314-May-05 18:21 
GeneralRe: Newbie: Q regarding Sorting DataGrid Pin
Gary Perkin17-May-05 5:58
Gary Perkin17-May-05 5:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.