About Monkey 2 › Forums › Monkey 2 Programming Help › network/socket/tcp read/write class ?
This topic contains 6 replies, has 3 voices, and was last updated by
gcmartijn 2 years, 7 months ago.
-
AuthorPosts
-
September 14, 2016 at 7:19 pm #3945
I’m searching for the most easy socket class for localhost debugging only at the moment.
So one window has
socket.connect(‘127.0.0.1’) (localhost)
if newdata then
data.read()
endand the other window ‘server’ has
createconnection()
data.send(“bla”)Target os at the moment just OSX
can’t find a easy way at the moment.
September 14, 2016 at 9:43 pm #3949This code is in development and no windows support yet but may be of use:
https://github.com/nitrologic/m2/blob/master/vhost/posix.monkey2
https://github.com/nitrologic/m2/blob/master/vhost/socket.monkey2
September 15, 2016 at 12:54 am #3951ipv6 socket support for mx1 has just reared it’s ugly head again, so I think I’ll get stuck into this right now!
September 15, 2016 at 9:45 am #3955@Simon Armstrong
Will check if I can use it, thanks
September 16, 2016 at 12:40 am #3958Monkey12345678910111213141516171819202122232425262728293031Function TestSocketConnect()Local s:=Socket.Connect("google.com",80)Local res:=s.Write("GET / HTTP/1.0~r~n~r~n")While TrueLocal t:=s.Read()If t.Length=0 ExitPrint tWends.Close()EndFunction TestSocketListen()Print "Listening on port 8080"Local s1:=Socket.Listen(8080)If s1=NullPrint "Listen failed"ReturnendifLocal s2:=s1.Accept()Print "Got Connection"While TrueLocal t:=s2.Read()If t.Length=0 ExitPrint tWendPrint "Lost Connection"s2.Close()s1.Close()EndSeptember 16, 2016 at 1:34 am #3959Just commited the ‘official’ std.socket.Socket and std.socket.SockerServer classes.
Very similar to Si’s work except:
- Only Read( ptr,count) and Write( ptr,count ) IO supported for now. Socket extends Stream so the intent is to add ReadString/WriteString etc to Stream.
- If called from a fiber, socket ops including connect, listen, accept, close, read and write are performed on a thread while the fiber suspends itself, ie: they wont lockup the gui. Lots of room for improvement in the implementation here (and there are vsync issues), but it makes client/server stuff about 10000 easier to write than in mx1 (see new echoserver banana).
- Only ‘stream’ sockets for now. Connection oriented datagrams should be very easy to add, connection-less will require more work, but are these even used any more? I think something WebSocket-ish (ie: a message/reply based protocol) should be next up!
- Should be completely ipv6 friendly.
Basically, it’s a WIP first attempt. The ‘new’ ipv6 friendly way to do sockets is much nicer to work with though.
September 16, 2016 at 10:43 am #3976@Mark
I wait till there is a little info about it in module docs
Edit:
Well the banana did give all the things I need yet, so no docs needed at the moment
-
AuthorPosts
You must be logged in to reply to this topic.