|
WSADATA wsd;
SOCKET cs = INVALID_SOCKET;
char ref[512];
char rb[512];
int iResult, ires, recvbuflen;
struct sockaddr_in sin;
char ctrl[3] = {'\r','\n','\0'};
string str;
str="";
iResult = WSAStartup(MAKEWORD(2,2), &wsd);
if(iResult!=0) { alert("Cannot init Winsock"); return; }
cs = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = inet_addr("127.0.0.1");
sin.sin_port = htons(27015);
bind(cs,(SOCKADDR *)&sin, sizeof(sin));
BOOL optval = TRUE;
int bOptLen = sizeof(optval);
int sokres = setsockopt(cs,SOL_SOCKET,SO_REUSEADDR, (char *)&optval,bOptLen);
txtMeans.setText("waiting...");
listen(cs,1);
int aks = accept(cs,NULL,NULL);
do {
ires = recv(cs,rb,512,0);
if(ires>0)txtMeans.setText(rb);
else if(ires==0)txtMeans.appText("Connection Closed");
else {
txtMeans.appText("Receive failed");
recvbuflen = WSAGetLastError();
getes(recvbuflen);
if(SOCKET_ERROR==ires)alert("yes");
alert(rb);
}
}while(ires>0);
closesocket(cs);
WSACleanup();
txtMeans.appText("Doni");
This is blocking and listening in the specified port...
i created another app which connects to that port and sends data.
as soon as the data is sent i the recv does its work and i get -1 but when i checked for
last error using wsagetlasterror it returns zero. then how am i supposed to find the problem?
for ease i created the sender using PHP by having appache in localhost
$cs = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
socket_connect($cs,'127.0.0.1',27015);
socket_write($cs,"hehehe");
socket_close($cs);
txtMeans is a wrapper to a multiline edit control
alert and pint are wrappers for msgbox
to be precise i run this program... it listens to that specified port.
blocking mode. then i run my php program it connects to that ip,port it sends the data
here in the server i get the alert like i have stated above.
-1 is returned but wasgetlasterror returns zero which mostly not supposed to.Today's Beautiful Moments are
Tomorrow's Beautiful Memories
modified on Monday, February 22, 2010 12:29 PM
|
|
|
|
|
I think you should be using recv on the "aks" socket returned from accept
|
|
|
|
|
haha, yes, exactly. thank you.
just now i found that and i was about to rejoice here to tell people that i made a little [misteyk]. now it is working. i should have refreshed the codeproject page so that i would have found the reply earlier and would have saved the time... Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
i want to know the code to add image in my c++ program
|
|
|
|
|
Where in your application ? on a button ? as the background of a dialog ? as a background of a CView derived class ?
Do you know how to load an image ?
Do you know how to display an image (in general)?Watched code never compiles.
|
|
|
|
|
|
How can i support MFC OLE drag and drop with image between two windows?
|
|
|
|
|
...with an aplication's mouse cursor[^]
|
|
|
|
|
|
when i change the digit substitution from "Control panel>Regional and Language Options>Regional Options>Customize" in (win xp), to "Natinal", all the numbers of my program change to other language.
How should i prevent changing the numbers of my program or how should i change the "digit substitution" to "Context" in mfc?
|
|
|
|
|
|
|
Hi all,
i m working on SMS sending application using AT commands.
for sms sending send +CMGS command than it return > to enter message,now this time if i stop the sending process,and than if i send message again from starting when i connect the port its return >.
please tell me how can i clear the previous command value,and fresh start for each new msg sending process.
thanks in advance.
|
|
|
|
|
Your question is not clear, can you try to explain again, or post some code to show what is not working? If you are just having trouble with the 'AT' commands themselves then you need to check your syntax is correct. txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
I mean what command can i use for reset.
|
|
|
|
|
One of these[^] should have the answer you need. txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
My problem is that.
i m sending cmgs command
AT+CMGS="+91986857485"<cr>
than it return ">"
here process is stop without completing the last command.
when again i want to communicate starting from sending AT command.
its return here also > instead of OK.
i want when i stop the process or whether start new process its start from initial.
so i want to reset this.
please help me for this.
thanks.
|
|
|
|
|
Le@rner wrote: i m sending cmgs command
AT+CMGS="+91986857485"
I don't see this command in the modem command set anywhere. I suggest you follow the link I gave you earlier, or consult the documentation for your modem to see what is the correct format.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Sir +CMGS is command to sending sms.
|
|
|
|
|
It's waiting for you to enter the data to send. That's what the > prompt means. Enter the data then use ^Z to end the input. It should then execute the command, display a return status and return to the waiting for next command state
JudyBe wary of strong drink. It can make you shoot at tax collectors - and miss.
Lazarus Long, "Time Enough For Love" by Robert A. Heinlein
|
|
|
|
|
Hello Friends
I am using visual Studio 2008 .net for creating c++ application on windowsXP but now I have to migrate our project in Linux.
Can u Please suggest me that which enviorement is suitable and professional to run application in Linux.
I saw on Internet and they suggest "Use the Visual Studio .NET IDE and Grasshopper to Deploy .NET Apps on Linux!" I hv no idea abt even GrassHopper and Is tht much for professionals?
Please suggest me something so I can proceed.
Thanks In Advance.
Regards
Yogesh Sikri
|
|
|
|
|
Such a self-contradictory post. Are you writing a C++ program or a .NET program (No, C++/CLI does not count as C++). If you're using C++, you could use one of the many cross-platform IDEs available.
See this link for a comparison of cross platform C/C++ IDEs: http://en.wikipedia.org/wiki/Comparison_of_integrated_development_environments#C.2FC.2B.2B[^]
By providing that link, I'm assuming that you've written portable code. For example, if you've used something like MFC, it is not portable to another OS. You should have used C++ and any of those libraries that are cross-platform.
If you're using C++/CLI, post your query in the C++/CLI forum.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
|
Thanks A Lot Guys.
Yogesh
|
|
|
|
|
If you are still interested in the .Net framework, i think Monodevelop is a good idea.
<a href="http://monodevelop.com/">http://monodevelop.com/</a>[<a href="http://monodevelop.com/" target="_blank" title="New Window">^</a>]
Hope it helps.Wamuti: Any man can be an island, but islands to need water around them!
Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
|
|
|
|