Click here to Skip to main content
15,889,034 members
Home / Discussions / C#
   

C#

 
GeneralRe: Calling C# class library in VC++6.0....... Pin
Nick Parker20-May-05 11:01
protectorNick Parker20-May-05 11:01 
QuestionHow do i make a program run at startup Pin
Anthony Mushrow20-May-05 7:33
professionalAnthony Mushrow20-May-05 7:33 
AnswerRe: How do i make a program run at startup Pin
Anonymous20-May-05 7:58
Anonymous20-May-05 7:58 
GeneralRe: How do i make a program run at startup Pin
Anthony Mushrow20-May-05 8:07
professionalAnthony Mushrow20-May-05 8:07 
GeneralRe: How do i make a program run at startup Pin
John Fisher20-May-05 9:23
John Fisher20-May-05 9:23 
AnswerRe: How do i make a program run at startup Pin
Anonymous20-May-05 12:01
Anonymous20-May-05 12:01 
AnswerRe: How do i make a program run at startup Pin
malharone20-May-05 12:05
malharone20-May-05 12:05 
GeneralSockets problem Pin
AnonymousTwo20-May-05 7:29
AnonymousTwo20-May-05 7:29 
Hello,

I have a problem with asynchronous sockets communication. I try to send an object from the server to the client by using the send method. In the client's ReceiveCallback I have put two breakpoints, one at line "if (bytesRead > 0) " which is hit, and one at line " bgForm.ReceiveObject(state.gameDataStream);" which never gets hit. What could be the reason? Thanks in advance.

The client code:

public static void StartClient(string ServerIPAddress, int port)
{
// Connect to a remote device.
try
{
IPAddress ipAddress = IPAddress.Parse(ServerIPAddress);
IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);

// Create a TCP/IP socket.
Socket client = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);

connectDone.Reset();
// Connect to the remote endpoint.
client.BeginConnect( remoteEP,
new AsyncCallback(ConnectCallback), client);
connectDone.WaitOne();

Receive(client);
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}

private static void ConnectCallback(IAsyncResult ar)
{
try
{
// Retrieve the socket from the state object.
Socket client = (Socket) ar.AsyncState;

// Complete the connection.
client.EndConnect(ar);

// Signal that the connection has been made.
state.workSocket = client;
connectDone.Set();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}

public static void Receive(Socket client)
{
try
{

// Begin receiving the data from the remote device.
client.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0,
new AsyncCallback(ReceiveCallback), state);

}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}

private static void ReceiveCallback( IAsyncResult ar )
{
try
{
// Retrieve the state object and the client socket
// from the asynchronous state object.
StateObject state = (StateObject) ar.AsyncState;
Socket client = state.workSocket;

// Read data from the remote device.
int bytesRead = client.EndReceive(ar);

if (bytesRead > 0)
{
// There might be more data, so store the data received so far.
state.gameDataStream.Write(state.buffer,0,bytesRead);

receiveDone.Reset();
// Get the rest of the data.
client.BeginReceive(state.buffer,0,StateObject.BufferSize,0,
new AsyncCallback(ReceiveCallback), state);
receiveDone.WaitOne();
}
else
{
// All the data has arrived; put it in response.
// Signal that all bytes have been received.
receiveDone.Set();
}
bgForm.ReceiveObject(state.gameDataStream);
client.BeginReceive(state.buffer,0,StateObject.BufferSize,0,
new AsyncCallback(ReceiveCallback), state);
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}

GeneralRe: Sockets problem Pin
John Fisher20-May-05 9:11
John Fisher20-May-05 9:11 
GeneralRe: Sockets problem Pin
AnonymousTwo20-May-05 10:11
AnonymousTwo20-May-05 10:11 
GeneralRe: Sockets problem Pin
John Fisher20-May-05 10:55
John Fisher20-May-05 10:55 
GeneralRe: Sockets problem Pin
AnonymousTwo20-May-05 11:24
AnonymousTwo20-May-05 11:24 
GeneralRe: Sockets problem Pin
John Fisher20-May-05 19:19
John Fisher20-May-05 19:19 
Generalprob with activex Pin
amalatsliit20-May-05 7:10
amalatsliit20-May-05 7:10 
GeneralDataBinding Format/Parse Event, can't raise the Parse Event Pin
Kaneda7920-May-05 5:48
Kaneda7920-May-05 5:48 
QuestionHow to register Hotkey for TextBox? Pin
oohungoo20-May-05 5:47
oohungoo20-May-05 5:47 
AnswerRe: How to register Hotkey for TextBox? Pin
Marc Clifton20-May-05 6:35
mvaMarc Clifton20-May-05 6:35 
GeneralPicturebox and tiff file Pin
Anonymous20-May-05 4:43
Anonymous20-May-05 4:43 
GeneralRe: Picturebox and tiff file Pin
Robert Rohde20-May-05 6:04
Robert Rohde20-May-05 6:04 
GeneralNetwork Utlization Pin
Zishan Haider20-May-05 4:05
Zishan Haider20-May-05 4:05 
GeneralNice Class and Method Descriptions Pin
zandries20-May-05 3:56
zandries20-May-05 3:56 
GeneralRe: Nice Class and Method Descriptions Pin
Judah Gabriel Himango20-May-05 4:28
sponsorJudah Gabriel Himango20-May-05 4:28 
GeneralRe: Nice Class and Method Descriptions Pin
zandries20-May-05 4:40
zandries20-May-05 4:40 
GeneralRe: Nice Class and Method Descriptions Pin
Anonymous20-May-05 4:46
Anonymous20-May-05 4:46 
GeneralRe: Nice Class and Method Descriptions Pin
MoustafaS20-May-05 14:39
MoustafaS20-May-05 14:39 

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.