View Full Version : Winsock based vs. full fledged server
Larry770
03-21-2005, 01:53 PM
Hi,
I'm trying to get one computer to run a file on another one remotely. Right now what I've done is set one of the computers to be a full fledged Apache web server, and the other one is just a regular one connected to the net. The client just logs onto the web page that has the simple code to trigger the program/file on the server.
Would the response time be quicker were one to set this up using Winsock programming? (I guess Java or similar...)
Thanks,
Larry
Dr. Evil
03-21-2005, 06:30 PM
It might be a little quicker if you made your client and server programs to do exactly what you wanted to do.
Yeah, response times should be a little quicker but make sure you're careful if you decide to make client and server apps with the purpose of running programs remotely.
Also, you can probably use any language you're familiar with to accomplish the task of client/server programming including Java, Python, C++, PHP, etc.
Larry770
03-21-2005, 10:54 PM
Thanks. BTW if I were to go the route of programming it myself, would that require a client program as well? The goal here would be that it could be triggered remotely from any computer connected to the internet (through a browser window or something similar...) Basically if the client would have to download something in order to execute the file, then it would be better just using a server...
Unless... could the server-side be done with a Java 'Servlet' and the client just uses a small applet embedded in a web page? (I'm not too familar with all this...)
Thanks,
Larry
the situation that you describe is kanda vague...
what are you trying to accomplish?
Larry770
03-22-2005, 12:11 AM
Simple (an example): I have a house, and a computer. If I'm somewhere else that has an internet connection, I want to be able to morse code to my house. So basically, I would need some way of executing the program called 'beep' and 'beep long' quickly in succession according to what I press...
The end result would be that someone sitting in China (I'm not a spy :-) ) could send more code to my house through his regular internet connection...
The best thing would be if he could do it without having to download anything (like a small VB program etc...) but if there would be a significant improvement then so be it...
Right now what I did if set the computer to act as aserver and gave permission to the server to execute these files. So all you have to do is log on to a web site and click one of the buttons and one of the programs runs over here. The thing is that there is a tiny delay of about 1/2 a second (maybe less)- could the other way shorten the delay?
Thanks,
Larry
Simple (an example): I have a house, and a computer.
OK. This even I can understand. I'm supposing you also have a phoneline that is somehow connected to your computer and that leaves the house.
If I'm somewhere else that has an internet connection, I want to be able to morse code to my house. So basically, I would need some way of executing the program called 'beep' and 'beep long' quickly in succession according to what I press...
Let me get this straight: you wanna use an advanced communication medium like internet to transport morse-code? You wanna activate programs over the web by sending requests in morse-code?
Why? Can't you just click on a link that then requests a PHP-page? This PHP page can then activate a program on the server.
If you just wanna shorten the delay by sending morsecode instead of an http-request, then i think you wount succeed. A delay (from hitting the button till activating the program) of 1/2 seconds is fairly fast, if you consider that the command needs to be transported, interpreted and executed.
Larry770
03-22-2005, 03:14 AM
Hi,
No the point is to run small programs like playing music or something where each note is a file (like 'beep1.bat' and 'beep2.bat' etc...) and they should be triggered remotely... The problem is that on the actual computer they execute very quickly- literally as quickly as you press enter, but when I set it up as a web server running Apache and then execute the files through a web browser (using a PHP 'EXEC' command in a form) even if I'm on the same computer just accessing the page as though I'm a visitor, there's a delay that makes somewhat of a difference. Now of course you'll never get truly instant as long as its a server running, but thats why I was thinking: maybe if I programmed something using Winsock or something and had some form of an applet or activex on the client side, then the delay might be much less...
Do you think that there would be a difference really? Because even though Apache is very quick it is nonetheless a full server and I'm thinking that maybe using another means would be faster...
If anyone has any ideas or answers, please let me know also *how* to do it (or at least point in the general direction) because I dont have too much experince yet in all this...
Thanks,
Larry
Dr. Evil
03-22-2005, 05:03 PM
You'd pretty much have to create a mini replacement for the Apache server. Thus, it would listen on port 80 for incoming HTTP commands and when it received the command, could execute the program on your computer.
Larry770
03-22-2005, 05:09 PM
If I were to somehow do that, do you think that there might be a quicker response time that the regular Apache server? Do you have any idea how much quicker? Because right now Apache is running as a service, and PHP is part of the server (ie. its not a separate exe...) so this should be pretty qucik, but nonetheless I do see a 1/4-3/4 second delay even if I'm using the local computer to access the page...
If you think it might be worth a try, do you have any suggestions as to where to turn to set it up?
Thanks,
Larry
A proper network server/client's response time would be very fast depending mostly on network latency, usually measured in milliseconds (try pinging a remote box to get an idea of response times) and would be almost instantaneous on a local network.
Larry770
03-22-2005, 10:08 PM
So where would I start? The point is that it should be accessible from a regular web browser window... (so I assume that Java Applet would do that, but I'm not too familiar with other options...)
Thanks,
Larry
Dr. Evil
03-22-2005, 10:14 PM
Well, for starters you could make a program to listen() in on port 80 and parse any recieved command. Here's a very simplistic server, if that helps at all. It only recieves info then prints it to the screen, but all you would have to do is replace that part with a code to parse HTTP requests and then execute programs/scripts on command.
#include <stdio.h>
#include <winsock2.h>
int ConnectSocketAsServer(int port)
{
WSADATA ws;
SOCKET sock, new_sock;
int size, ret, r;
struct sockaddr_in serv_addr, cli_addr;
char buffer[MAX_PATH], host[MAX_PATH];
ret = -1;
if(WSAStartup(MAKEWORD(2,0), &ws) == 0)
{
if((sock = socket(AF_INET, SOCK_STREAM, 0)) != INVALID_SOCKET)
{
ZeroMemory(&serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(port);
if(bind(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) != SOCKET_ERROR)
{
listen(sock, 6); //call cannot fail if a valid socket is used
gethostname(host, MAX_PATH);
printf("Bound on %s to port %d\nListening...\n", host, port);
size = sizeof(cli_addr);
if((new_sock = accept(sock, (struct sockaddr*)&cli_addr, &size)) != INVALID_SOCKET)
{
size = sizeof(cli_addr);
getpeername(new_sock, (struct sockaddr*)&cli_addr, &size);
printf("Accepted connection from %d.%d.%d.%d\n", cli_addr.sin_addr.S_un.S_un_b.s_b1,
cli_addr.sin_addr.S_un.S_un_b.s_b2,
cli_addr.sin_addr.S_un.S_un_b.s_b3,
cli_addr.sin_addr.S_un.S_un_b.s_b4);
while(1)
{
ret = 0;
memset(buffer, 0, MAX_PATH);
if((r = recv(new_sock, buffer, (MAX_PATH-1), 0)) == SOCKET_ERROR) {ret = 4; break;}
if(r == 0)
{
puts("The connection was lost");
close(sock);
break;
}
else
{
puts(buffer);
}
}
}
else ret = 3;
}
else ret = 2;
}
else ret = 1;
WSACleanup();
}
else ret = 6;
return ret;
}
int main(int argc, char *argv[])
{
char *error;
if(argc != 2) {printf("Usage: %s [port num]", argv[0]); return 1;}
switch(ConnectSocketAsServer(atoi(argv[1])))
{
case 0 : error = "ConnetSocketAsServer() successfully returned"; break;
case 1 : error = "Unable to create socket"; break;
case 2 : error = "Unable to bind socket"; break;
case 3 : error = "Unable to accept socket"; break;
case 4 : error = "Error whilst recieving info"; break;
case 5 : error = "Error whilst sending info"; break;
case 6 : error = "Failure to call WSAStartup()"; break;
case -1 : default :
error = "Unkown error"; break;
}
puts(error);
return 0;
}
Larry770
03-22-2005, 10:27 PM
Thanks, but now according to this what I'd do is create a mini server which would pick up tcp/ip traffic to its port and translate it to a command... If thats the case, why wouldnt I just use a tiny little micro web server that I'm sure is somewhere out there and have it so the job? In the end of the day all this is doing is creating a mini-server anyway, no?
Unless- is there a way to have this program run as a service in the background like a 'daemon'?
Thanks,
Larry
Dr. Evil
03-22-2005, 10:43 PM
Yes, it is possible to make it as a service, but I'm afraid I have no experience in such a field. However, an MSDN technical article about creating a C++ service can be found here (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndllpro/html/msdn_ntservic.asp).
Larry770
03-22-2005, 10:52 PM
Ok thanks. Right now I'm going to look for a very small server, but I might do this if nothing is small or quick enough...
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.