15,897,371 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by ayesha hassan (Top 56 by date)
ayesha hassan
16-May-13 7:58am
View
Thank you so much :)
ayesha hassan
13-May-13 1:56am
View
I had been working on a Server Client aplication where Server is going to service(sendto + receivefrom) 'x' number of Clients at a time. For this purpose, I have created 'x' number of threads on Server side so that each thread is dadicated to one single client. Inside each thread there is a specific socket for just for its client. I was thinking to make these sockets non-blocking but now I think using blocking socket inside each thread is a better Idea. Blocking Socket continuously waits to receive data and when ever there is a need to send anything, sendto() is called. Is using blocking Socket in such a situation a good approach or should I use non-blocking sockets? :(
Waiting for help!!!
ayesha hassan
10-May-13 6:02am
View
Got that. Thank you :)
ayesha hassan
10-May-13 5:34am
View
Always helpful :)
ayesha hassan
10-May-13 4:57am
View
My mistake, thank you for the suggestion :)
ayesha hassan
10-May-13 4:56am
View
even
"r+b"
is working fine. Can you explain a little further why do you prefer
"rb"
?
ayesha hassan
10-May-13 4:54am
View
while(fpSend!=NULL)
{
int bytes_read=0;
if((bytes_read=fread(file_buffer, 1,12, fpSend))<=0)
{
if(feof(fpSend))
{
//"End of File Found";
return 0;
}
else
{
//"fread() failed"
return 0;
}
}
Is it what you meant?
ayesha hassan
10-May-13 3:57am
View
I think this is going to work. Infact, Wouldn't it be better to read only fixed number of bytes using fread(), transfer them over the socket and then read the next bytes?
By the way, Thank you so much :)
ayesha hassan
10-May-13 1:40am
View
Deleted
Thank you for the help.
File format is known i.e. ".txt". The data types of the contents inside file may vary. e.g file may have chars + int or only int or only char etc.
ayesha hassan
10-May-13 1:39am
View
Read one line from a text file using fgets() and stored it in char[] but what I get is corrupted data :(
ayesha hassan
10-May-13 1:35am
View
I guess file format i.e. ".txt" is defined :(
The data types of the contents inside the file is not known. i.e file may have char as well as int.
ayesha hassan
10-May-13 1:33am
View
Deleted
Thank you for the help.
File format is known i.e. ".txt". The data types of the contents inside file may vary. e.g file may have chars + int or only int or only char etc.
ayesha hassan
9-May-13 4:41am
View
@CPallini : Once again you have solved it :)
ayesha hassan
9-May-13 4:39am
View
I am sorry for improper indentation. I am going to fix that :)
ayesha hassan
9-May-13 0:48am
View
I got the idea now :)
ayesha hassan
8-May-13 8:05am
View
OMG. When I was posting this question, I was dead sure that nobody is going to go through a code this long. I am shocked to see that people here are so helping that they spare their time to find out the stupid errors made by people like me :) I am really thankful for the help :)
ayesha hassan
8-May-13 2:05am
View
+1, Problem Solved :)
ayesha hassan
8-May-13 0:56am
View
+1. Thank you for the explanation
ayesha hassan
7-May-13 4:13am
View
+1 for the help :) Thanks a lot
ayesha hassan
7-May-13 4:13am
View
+1 for the help :) Thanks a lot
ayesha hassan
7-May-13 4:13am
View
Thank you so much. It works now :)
ayesha hassan
7-May-13 2:33am
View
I shifted towards the idea of using non blocking sockets when I realized that my Server is blocking in continuous call to recvfrom() and is unable to send anything even if it wants, unless call to recvfrom() ends.
e.g:
while(1)
{
if((recv_len = recvfrom(AH_glb_ackSocketIdentifier, receiveBuffer, sizeof(receiveBuffer), 0, (struct sockaddr *) &acksocket, &socketLength)) == SOCKET_ERROR)
{
//recvfrom() Failure.
}
if (sendto(socketIdentifier,sendBuffer,strlen(sendBuffer) , 0 , (struct sockaddr *) &AH_glb_connectedSocket, sizeof(AH_glb_connectedSocket)) == SOCKET_ERROR)
{
//sento() Failure
}
}
ayesha hassan
3-May-13 2:20am
View
Thank you so much :) It is working now :)
ayesha hassan
2-May-13 5:07am
View
Thank you so much for such an explanatory answer :)
ayesha hassan
2-May-13 5:06am
View
Thank you so very much for the help :)
ayesha hassan
20-Apr-13 1:48am
View
Thank you for the explanation :)
ayesha hassan
20-Apr-13 1:19am
View
I have always followed the concept that multithreading can only be implemented on multiple processors system where there are more than one processor to be assigned to each thread and each thread can be executed simultaneoulsy. There is no scheduling in this case as each of the thread has separate resources all dedicated to it.
what is the difference between single processor and multiple processor systems then? :(
I have posted another question here
http://www.codeproject.com/Questions/580778/Canplusmultithreadingplusbeplusimplementedplusonpl
ayesha hassan
19-Apr-13 7:05am
View
If I have a single processor system and I can not implement multithreading, what am I supposed to do then in order to handle multiple clients in my server? :(
ayesha hassan
17-Apr-13 6:59am
View
5.
ayesha hassan
17-Apr-13 6:53am
View
5.
ayesha hassan
15-Apr-13 8:08am
View
For that do I need one main receiving thread and distribute the incoming clients on the basis of their IP addresses to specific threads?
ayesha hassan
12-Apr-13 7:24am
View
@jsolutions_uk : Thanks for sharing about receive queue. But upto what limit will the data be queued in such a buffer? There must be a limit after which the queue is full and moreincoming data will be discarded, if I'm not worng in understanding the concept.
ayesha hassan
12-Apr-13 7:18am
View
but there is no connect() or listen() in UDP :(
ayesha hassan
12-Apr-13 7:16am
View
Thank you so much. Your answer is really helpful, but the problem is that I am working on UDP and UDP does not listen(). listen() is avialable only in TCP as far as I know :(
ayesha hassan
12-Apr-13 7:10am
View
If there is only a single thread and all of the 40 clients send data simultaneously on this single socket, there are chances that data of each client may get dropped.
Due to this reason, I shifted towards creating dedicated sockets for each client.
ayesha hassan
12-Apr-13 5:38am
View
if data arrives from 40 clients at a socket, it will be buffered in socket buffer right? and each call to recvfrom() will read data from socket buffer
ayesha hassan
11-Apr-13 8:06am
View
Thank you for the help, but this function changes the name of PC after the system is restarted while I want to change the name as soon as the function is called.
ayesha hassan
10-Apr-13 8:29am
View
so I should copy only buffer[0] to buffer[byres_read-1] to some other new buffer and then send that new buffer over the socket?
ayesha hassan
10-Apr-13 8:23am
View
still the same :(
ayesha hassan
10-Apr-13 7:21am
View
and now the error:
error C2664: 'WriteFile' : cannot convert parameter 2 from 'int' to 'LPCVOID'
ayesha hassan
10-Apr-13 7:13am
View
fpFile = fopen("sendclInformation.txt", "r+");
fseek(fpFile, 0, SEEK_SET);
WriteFile(file,EOF,strlen(EOF),&dwWritten,0);
I tried this but:
error C2664: 'strlen' : cannot convert parameter 1 from 'int' to 'const char *'
ayesha hassan
2-Apr-13 6:54am
View
Below is the latest code that I am trying:
char ip[32];
int port;
DWORD dwWritten;
FILE *fpOriginal, *fpOutput;
HANDLE hFile,tempFile;
hFile=CreateFile("Hell.txt",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
tempFile=CreateFile("temp.txt",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
WriteFile(hFile,"10.0.1.25 524192\r\n\r\n10.0.1.25 524193\r\n\r\n",strlen("10.0.1.25 524192\r\n\r\n10.0.1.25 524193\r\n\r\n"),&dwWritten,0);
fpOriginal = fopen("Hell.txt", "r+");
fpOutput = fopen("temp.txt", "w+");
while (fscanf(fpOriginal, " %s %d", ip, &port) > 0)
{
printf("\nLine1:");
printf("ip: %s, port: %d", ip, port);
char portbuff[32], space[]=" ";
sprintf(portbuff, "%i",port);
strcat(ip," ");
strcat(ip,portbuff);
if(port == 524192)
printf("\n Delete this Line now");
else
WriteFile(tempFile,ip,strlen(ip),&dwWritten,0);
}
fclose(fpOriginal);
fclose(fpOutput);
CloseHandle(hFile);
CloseHandle(tempFile);
remove("Hell.txt");
if(!(rename("temp.txt","Bye.txt")))
{
printf("\ncould not rename\n");
}
else
printf("\nRename Done\n");
//remove ("Hell.txt");
ayesha hassan
2-Apr-13 6:48am
View
And now another issue, sometimes, rename() fails as well, once in twenty tries.
ayesha hassan
2-Apr-13 6:38am
View
I see two strange behaviours here.
1. Placing remove() before rename() gives an error while rename()ing the file.
2. Placing remove() after rename() does not rename the file but generates a new file :\
ayesha hassan
2-Apr-13 4:59am
View
Could it be an issue due to the attributes I used while using CreateFile()?
ayesha hassan
2-Apr-13 4:54am
View
Thank you :) I closed the file, then checked. even the rename() function succeeds still the file is not renamed or deleted :(
ayesha hassan
2-Apr-13 4:44am
View
Updated my question for you :)
ayesha hassan
2-Apr-13 4:38am
View
I know its all my mistake posting a stupid question + the typo.
I am really sorry :(
ayesha hassan
2-Apr-13 4:34am
View
Thank you so much CPallini.
I followed your instructions and worte this code. Now the line I wanted to delete is successfully removed in my output file, but the last step of deleting the original file and renaming the output file is not working. Please tell me what wrong am I doing.
char ip[32];
int port;
DWORD dwWritten;
FILE *fp;
HANDLE hFile,tempFile;
hFile=CreateFile("Hell.txt",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
tempFile=CreateFile("temp.txt",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
WriteFile(hFile,"10.0.1.25 524192\r\n\r\n10.0.1.25 524193\r\n\r\n",strlen("10.0.1.25 524192\r\n\r\n10.0.1.25 524193\r\n\r\n"),&dwWritten,0);
fp = fopen("Hell.txt", "r+");
while (fscanf(fp, " %s %d", ip, &port) > 0)
{
printf("\nLine1:");
printf("ip: %s, port: %d", ip, port);
char portbuff[32], space[]=" ";
sprintf(portbuff, "%i",port);
strcat(ip," ");
strcat(ip,portbuff);
if(port == 524192)
printf("\n Delete this Line now");
else
WriteFile(tempFile,ip,strlen(ip),&dwWritten,0);
}
remove ("Hell.txt");
rename("temp.txt","Hell.txt");
ayesha hassan
2-Apr-13 3:48am
View
Thank you so much. looks useful to me but sounds complex :( I am new in this, can you give me an example?
ayesha hassan
1-Apr-13 3:27am
View
Thank you so much :)
ayesha hassan
30-Mar-13 0:40am
View
I am creating a .txt file for this purpose. Is it right ?
ayesha hassan
29-Mar-13 5:47am
View
Your posts are always very helpful :)
Thanks alot again Matthew Faithfull :)
ayesha hassan
29-Mar-13 4:11am
View
I preffer using single Sokcet and one thread for recvfrom() receiving data from all clients and 40 threads fro procssing this data. What do you suggest now?
ayesha hassan
29-Mar-13 0:50am
View
Thank you everyone for the help, but since I am beginner in this, I am a little confused that waht happens if I create 40 threads and few of the thread try to write at the socket simultaneously? (Since there is only one socket for data reception and sending)
ayesha hassan
28-Mar-13 7:40am
View
What have you tried so far? Do you have any piece of code that you tried? Please share that as well.
Show More