1. Simple Socket Setup
I am trying to figure out how to set up
a transfer from one computer to another.
I will use two separate progs; one for
Tx and one for Rx. I would like to know
the simplest possible program to send a
3 digit number from Tx to Rx whenever an
event ocurrs (A button is pushed).
I would HUGELY appreciate it if someone
could show me how to create such a
program using sockets.
Thanks... Andy
2. Re: Simple Socket Setup
On Mon, 10 Jan 2000 10:43:37 -0500, Andy Briggs <briggsan at HOTMAIL.COM>
wrote:
>I am trying to figure out how to set up
>a transfer from one computer to another.
>I will use two separate progs; one for
>Tx and one for Rx. I would like to know
>the simplest possible program to send a
>3 digit number from Tx to Rx whenever an
>event ocurrs (A button is pushed).
>I would HUGELY appreciate it if someone
>could show me how to create such a
>program using sockets.
>
>Thanks... Andy
Andy,
I wrote a generic server that will demonstrate how to use the
SM_ASYNC 'event' to handle opening, reading, and closing connections to
a remote machine. You can find it in the downloads section of my site at
http://2fargon.hypermart.net.
As for the client, include srvsckip.ew (included with the server demo), and
do something like this:
-- UNTESTED CODE! USE AT YOUR OWN RISK!
-- requres win32lib.ew and srvsckip.ew
global atom mySocket
procedure onOpenMainWindow()
-- executes at the onOpen event
object errorRtn
errorRtn = WsockInit() -- initialize winsock
if errorRtn then
abort(1) -- couldn't initialize
end if
mySocket = WsockCallSocket("127.0.0.1",80)
-- the two parameters are IP address and port number. Set them as
-- appropriate for your server program
end procedure
procedure onClickButton()
-- called when the button is clicked
sequence data
object errorRtn
data = "123"
-- or use whatever logic you like to format the data
errorRtn = WsockSendData(mySocket, data)
-- this function sends the sequence data to the server
end procedure
-- end code
Hope this helps, and feel free to ask lots more questions. I know I had
to when I was trying to figure all this stuff out!
Brian
3. Re: Simple Socket Setup
Thank you VERY much Brian.
That is EXACTLY what I was looking for...
Right now I have a program that reads and
writes to the parallel port. I would
like to be able to split the program up
and control it remotely over the internet.
This info will get me started but I'm
sure I will have many more questions for you.
Thanks... Andy
4. Re: Simple Socket Setup
Every time I try to send data to an IP address I get an error.
Since I don't have the full version of Ephoria, I cannot
view the error. The error occurrs on the statement
errorRtn = WsockSendData(mySocket, data). Why is this error
occurring. I am at work and am on a local network, but I
think the IP addresses are correct. Here is a copy of your
program with a few necessary changes. By the way, does it
matter which socket I use? I know that alot of them are
reserved, but can I use them anyways.
Thanks... Andy
5. Re: Simple Socket Setup
Every time I try to send data to an IP address I get an error.
Since I don't have the full version of Ephoria, I cannot
view the error. The error occurrs on the statement
errorRtn = WsockSendData(mySocket, data). Why is this error
occurring. I am at work and am on a local network, but I
think the IP addresses are correct. Here is a copy of your
program with a few necessary changes. By the way, does it
matter which socket I use? I know that alot of them are
reserved, but can I use them anyways.
Thanks... Andy
include win32lib.ew
include srvsckip.ew
global integer button1,MainWindow
global atom mySocket
procedure onOpenMainWindow()
--This procedure seems to work fine
-- executes at the onOpen event
object errorRtn
errorRtn = WsockInit() -- initialize winsock
if errorRtn then
abort(1) -- couldn't initialize
end if
--I am trying to use the IP of the computer next to me
mySocket = WsockCallSocket("142.2.132.29",23)
-- the two parameters are IP address and port number. Set them as
-- appropriate for your server program
end procedure
button1 = create(3,"send 123 to socket#80", MainWindow, 10,10 ,350,40, 0 )
procedure onClickButton()
-- called when the button is clicked
sequence data
object errorRtn
data = "123"
-- or use whatever logic you like to format the data
--This is the line that is causing the problems
errorRtn = WsockSendData(mySocket, data)
-- this function sends the sequence data to the server
end procedure
onClick[button1] = routine_id("onClickButton")
WinMain(MainWindow,Normal)
6. Re: Simple Socket Setup
OK I got it to work. Now I need to figure out
how to get the other computer to recieve the data.
The server program responds to, so I assume it
is working.
If anyone has a very simple example of this
I would like to take a look at it. The Server
program seems fairly complicated to me.
7. Re: Simple Socket Setup
>By the way, does it
>matter which socket I use?
As long as you use the same one on both the client and the server, you're
fine.
>I know that alot of them are
>reserved, but can I use them anyways.
>Thanks... Andy
There are some standards, 80 for HTTP, 21 for FTP, and so on, but there's
no law that says you have to use them for that purpose. As a standard rule
any sock > 1023 is used for a user-defined protocol or private transmission.
The problem with your code is that mySocket never gets assigned a value
because you forgot to hook into the onOpen event. Add this line of code
after the onOpenMainWindow() procedure:
onOpen[MainWindow] = routine_id("onOpenMainWindow")
That should do the trick...
Brian
8. Re: Simple Socket Setup
On Mon, 10 Jan 2000, you wrote:
> Every time I try to send data to an IP address I get an error.
> Since I don't have the full version of Ephoria, I cannot
> view the error. The error occurrs on the statement
> errorRtn = WsockSendData(mySocket, data).
You might want to try Pete's RDC program. It worked first try for me, and
is only about 2k bytes, so it shouldn't be hard to figure out how it works
and add whatever functions you need.
Regards,
Irv
9. Re: Simple Socket Setup
----- Original Message -----
From: Andy Briggs <briggsan at HOTMAIL.COM>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Monday, January 10, 2000 10:18 AM
Subject: Re: Simple Socket Setup
> Right now I have a program that reads and
> writes to the parallel port.
Can i see it?
>I would
> like to be able to split the program up
> and control it remotely over the internet.
Same here.
Thanks,
Kat
10. Re: Simple Socket Setup
--Here it is Kat.
--This is My Cool Little 8-Bit Parallel Port Program So Far...
--by Andy Briggs
--Saint John
--NewBrunswick
--Canada
include win32lib.ew
include Ports.e
global integer
ext1,decValue
constant AndyWin = create( Window, "Windows Parallel Port Program", 0,
Default, Default, 400, 300, 0 )
val=0
button1 = create(4,"button1", AndyWin, 10,10 ,12,14, 0 )
procedure onClick_button1()
--Add or subtract bit value from val depending on active state
if isChecked(button1) then
val=val+1
else
val=val-1
end if
setScrollPos( slider, val )
if val=0 then setScrollPos( slider, 1 ) end if
end procedure
onClick[button1] = routine_id("onClick_button1")
button2 = create(4,"button2", AndyWin, 10,30 ,12,14, 0 )
procedure onClick_button2()
--Add or subtract bit value from val depending on active state
if isChecked(button2) then
val=val+2
else
val=val-2
end if
setScrollPos( slider, val )
if val=0 then setScrollPos( slider, 1 ) end if
end procedure
onClick[button2] = routine_id("onClick_button2")
button3 = create(4,"button3", AndyWin, 10,50 ,12,14, 0 )
procedure onClick_button3()
--Add or subtract bit value from val depending on active state
if isChecked(button3) then
val=val+4
else
val=val-4
end if
setScrollPos( slider, val )
if val=0 then setScrollPos( slider, 1 ) end if
end procedure
onClick[button3] = routine_id("onClick_button3")
button4 = create(4,"button4", AndyWin, 10,70 ,12,14, 0 )
procedure onClick_button4()
--Add or subtract bit value from val depending on active state
if isChecked(button4) then
val=val+8
else
val=val-8
end if
setScrollPos( slider, val )
if val=0 then setScrollPos( slider, 1 ) end if
end procedure
onClick[button4] = routine_id("onClick_button4")
button5 = create(4,"button5", AndyWin, 10,90 ,12,14, 0 )
procedure onClick_button5()
--Add or subtract bit value from val depending on active state
if isChecked(button5) then
val=val+16
else
val=val-16
end if
setScrollPos( slider, val )
if val=0 then setScrollPos( slider, 1 ) end if
end procedure
onClick[button5] = routine_id("onClick_button5")
button6 = create(4,"button6", AndyWin, 10,110 ,12,14, 0 )
procedure onClick_button6()
--Add or subtract bit value from val depending on active state
if isChecked(button6) then
val=val+32
else
val=val-32
end if
setScrollPos( slider, val )
if val=0 then setScrollPos( slider, 1 ) end if
end procedure
onClick[button6] = routine_id("onClick_button6")
button7 = create(4,"button7", AndyWin, 10,130 ,12,14, 0 )
procedure onClick_button7()
--Add or subtract bit value from val depending on active state
if isChecked(button7) then
val=val+64
else
val=val-64
end if
setScrollPos( slider, val )
if val=0 then setScrollPos( slider, 1 ) end if
end procedure
onClick[button7] = routine_id("onClick_button7")
button8 = create(4,"button8", AndyWin, 10,150 ,12,14, 0 )
procedure onClick_button8()
--Add or subtract bit value from val depending on active state
if isChecked(button8) then
val=val+128
else
val=val-128
end if
setScrollPos( slider, val )
if val=0 then setScrollPos( slider, 1 ) end if
end procedure
onClick[button8] = routine_id("onClick_button8")
decValue = create(16,"", AndyWin, 10,165 ,40,14, 0 )
slider = create(VScroll,"", AndyWin, 28,10 ,10,150, 0 )
setScrollRange( slider, 1, 255 )
procedure onScroll_slider(integer pos)
integer result
setText(decValue,sprint(pos))
Output(pos,#378)--This sends o/p to port
result=pos+1
--Calculate new binary code
if result-128>0 then
result=result-128
setCheck(button8,1)
else
setCheck(button8,0)
end if
if result-64>0 then
result=result-64
setCheck(button7,1)
else
setCheck(button7,0)
end if
if result-32>0 then
result=result-32
setCheck(button6,1)
else
setCheck(button6,0)
end if
if result-16>0 then
result=result-16
setCheck(button5,1)
else
setCheck(button5,0)
end if
if result-8>0 then
result=result-8
setCheck(button4,1)
else
setCheck(button4,0)
end if
if result-4>0 then
result=result-4
setCheck(button3,1)
else
setCheck(button3,0)
end if
if result-2>0 then
result=result-2
setCheck(button2,1)
else
setCheck(button2,0)
end if
if result-1>0 then
result=result-1
setCheck(button1,1)
else
setCheck(button1,0)
end if
val=pos
end procedure
onScroll[slider] = routine_id("onScroll_slider")
WinMain( AndyWin, Normal )
11. Re: Simple Socket Setup
----- Original Message -----
From: Andy Briggs <briggsan at HOTMAIL.COM>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Tuesday, January 11, 2000 5:46 AM
Subject: Re: Simple Socket Setup
> --Here it is Kat.
> --This is My Cool Little 8-Bit Parallel Port Program So Far...
> --by Andy Briggs
Nice, Andy,, spiffy even!
I don't have anything on the port so i can't see if it worked, but it didn't
crash.
Thanks!
Kat