Click here to Skip to main content
15,895,142 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to get all environment variable of a process Pin
Luc Pattyn23-Jul-07 3:00
sitebuilderLuc Pattyn23-Jul-07 3:00 
GeneralRe: How to get all environment variable of a process Pin
SteveA6923-Jul-07 22:57
SteveA6923-Jul-07 22:57 
QuestionIs there a way to sort Listview columns numericly? Pin
Minosknight19-Jul-07 7:55
Minosknight19-Jul-07 7:55 
AnswerRe: Is there a way to sort Listview columns numericly? Pin
BoneSoft19-Jul-07 8:08
BoneSoft19-Jul-07 8:08 
GeneralRe: Is there a way to sort Listview columns numericly? Pin
Minosknight19-Jul-07 8:11
Minosknight19-Jul-07 8:11 
QuestionHow to use Backgroundworker for data transer? Pin
Khoramdin19-Jul-07 6:40
Khoramdin19-Jul-07 6:40 
AnswerRe: How to use Backgroundworker for data transer? Pin
Manas Bhardwaj19-Jul-07 7:05
professionalManas Bhardwaj19-Jul-07 7:05 
Questionproblems with incoming messages Pin
donjubs19-Jul-07 6:34
donjubs19-Jul-07 6:34 
hello.

i am working on an irc client and now i've got two problems. i hope someone can help me ;D
i use asynchronous sockets.

1) the byte array i fill, is sooner or later filled completely. but i don't know how to clear the array and when i have to clear it, or do i even have to clear it? as soon as the array is full, the program throws - of course - an exception ("ArgumentOutOfRangeException").

2) sometimes i get the same input more than one time. for example: when i join a channel and save the nicknames to the nicklist, some nicknames appear twice or even more often. what do i have to do that this doesnt happen?

the code:
private byte[] data = new byte[4096];
public void InitSocket()
{
    client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    client.Blocking = false;
    IPEndPoint ipe = new IPEndPoint(IPAddress.Parse("194.124.229.58"), 6667);
    client.BeginConnect(ipe, new AsyncCallback(OnConnect), client);
}
public void OnConnect(IAsyncResult ar)
{
    Socket remote = (Socket)ar.AsyncState;
    remote.EndConnect(ar);
    remote.BeginReceive(data, 0, data.Length, SocketFlags.None, new AsyncCallback(OnReceive), remote);
}
public void OnReceive(IAsyncResult ar)
{
    Socket remote = (Socket)ar.AsyncState;
    int received = remote.EndReceive(ar);
    if (received == 0)
    {
        client.Close();
        return;
    }
    string receivedtext = Encoding.Default.GetString(data, 0, received);
    sw.Invoke(Addmsg, new string[] { receivedtext }); // exception when data is full
    remote.BeginReceive(data, 0, data.Length, SocketFlags.None, new AsyncCallback(OnReceive), remote);
}


if you have improvements on my code, please tell me ;D

kind regards
AnswerRe: problems with incoming messages Pin
Judah Gabriel Himango19-Jul-07 7:41
sponsorJudah Gabriel Himango19-Jul-07 7:41 
GeneralRe: problems with incoming messages Pin
donjubs19-Jul-07 7:51
donjubs19-Jul-07 7:51 
GeneralRe: problems with incoming messages Pin
Judah Gabriel Himango19-Jul-07 8:05
sponsorJudah Gabriel Himango19-Jul-07 8:05 
GeneralRe: problems with incoming messages Pin
donjubs19-Jul-07 9:13
donjubs19-Jul-07 9:13 
GeneralRe: problems with incoming messages Pin
Judah Gabriel Himango19-Jul-07 9:46
sponsorJudah Gabriel Himango19-Jul-07 9:46 
GeneralRe: problems with incoming messages Pin
donjubs19-Jul-07 9:51
donjubs19-Jul-07 9:51 
GeneralRe: problems with incoming messages Pin
Judah Gabriel Himango20-Jul-07 7:25
sponsorJudah Gabriel Himango20-Jul-07 7:25 
GeneralRe: problems with incoming messages Pin
donjubs20-Jul-07 12:35
donjubs20-Jul-07 12:35 
GeneralRe: problems with incoming messages Pin
Judah Gabriel Himango21-Jul-07 11:56
sponsorJudah Gabriel Himango21-Jul-07 11:56 
GeneralRe: problems with incoming messages Pin
donjubs22-Jul-07 11:34
donjubs22-Jul-07 11:34 
GeneralRe: problems with incoming messages Pin
Judah Gabriel Himango23-Jul-07 6:06
sponsorJudah Gabriel Himango23-Jul-07 6:06 
AnswerRe: problems with incoming messages Pin
pbraun19-Jul-07 13:09
pbraun19-Jul-07 13:09 
GeneralRe: problems with incoming messages Pin
donjubs20-Jul-07 6:32
donjubs20-Jul-07 6:32 
QuestionTreeView Node focus Pin
topksharma198219-Jul-07 6:28
topksharma198219-Jul-07 6:28 
AnswerRe: TreeView Node focus Pin
Abisodun19-Jul-07 7:35
Abisodun19-Jul-07 7:35 
QuestionArchitecture question Pin
ssack19-Jul-07 6:24
ssack19-Jul-07 6:24 
QuestionSending Data to Sql Database Pin
Civic0619-Jul-07 5:28
Civic0619-Jul-07 5:28 

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.