May 29, 2024, 06:58:20 AM


IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!

Web server

Started by spud, March 17, 2020, 06:08:04 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


March 17, 2020, 06:08:04 AM Last Edit: March 17, 2020, 06:10:24 AM by spud
i've just bought the networking library which is great thanks for all the work put into creating it.

What i'm trying to do is create a simple web server which i can use to pass messages to my Ai program. I have already written a server program but it was a struggle which is why i bought the networking command set which seems to make life loads easier.

My problem is i can't work out how to extract text sent from the client. In my case the client is a browser program like internet explorer or Chrome. In my original server program i get lots of text from the browser which i then use to extract text like cookie information and text entered into a form.

I'm struggling to get this information from the IWNCS command set. I've got it to the point where the remote browser connects to my program which accepts the connection then sends a page back and closes the connection. The client then types into the form edit box and presses send or enter the information is sent back to the server. When i read the data using IWNCSReadData or IWNCSREADDATASTRING all i get is unreadable text in the debug output. Any help or ideas would be great i've tried allsorts of things but don't seem to be getting anywhere. Below is the code i'm using to read the data, the pb: output shows nothing the b2: output produces this: b2: D]´ÿ[¼Œ£^@eThÿ[ 9
I'm sure i'm getting confused by pointers but i can't work out what i'm doing wrong!

   ncsStatus = IWNCSReadData(DataSockets[client],pBuffer,LEN(pBuffer),0)
   bufferTwo = ""
   bufferTwo = #<string>pBuffer
   IF Debug = 1 THEN DEBUGPRINT "pb: " + bufferTwo
   bufferTwo = ""
   FOR LoopInt = 1 to datalen
      IF buffer[LoopInt] <> 0
         bufferTwo = bufferTwo + CHR$(pbuffer[LoopInt])
   NEXT LoopInt
   IF Debug = 1 THEN DEBUGPRINT "b2: " + bufferTwo



Nice to talk to you!

Don't know to much about the networking side of things, but attached is a set of simple commented programs I wrote for myself and as a tutorial regarding pointers.

Start with program a1, then a2 etc...

Attached are the examples - hope they help you.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.


Thanks Andy they look perfect!
I've manage to solve my problem it was down to when i do the read command.

This library is a dream to work with i'm managing to do things that took me months to do when i was writing my original program and having to deal with sockets. also that program was cobbled together from bits of code and information i could find. These commands make it much easier and a lot more stable, so far my server works fine with every browser i've tried it with.

One thing i haven't manged to work out is what to send to the browser so it knows its getting an image, at the moment it downloads the image rather than displaying it!


You can try to send a basic HTML page containing the picture link.
Something like this :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
  <link rev="made" href="mailto:adress">
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta name="generator" content="NoteTab Pro 4.92">
  <meta name="author" content="name">
  <meta name="description" content="Description">
  <meta name="keywords" content="keywords">

<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">


<p>... Type content here!</p>
<img src="image/filename.jpg" border="0" alt="Description">
<p><small>Created on ... march 20, 2020</small></p>


That seems to work, whether it displays the image or downloads it seems to be on what the browser is expecting to receive from the server.

I think i've now got it working on most browsers, old versions of internet explorer were causing problems so i needed a bit of a fix to get it to read the postvar input properly!