# Help for wifiServer

**URL:** <https://forum.arduino.cc/t/help-for-wifiserver/1272860>\
**Category:** Libraries\
**Created:** [June 18, 2024, 12:53am UTC](https://forum.arduino.cc/t/help-for-wifiserver/1272860 "2024-06-18T00:53:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukjar](https://avatars.discourse-cdn.com/v4/letter/l/59ef9b/32.png) [@lukjar](https://forum.arduino.cc/u/lukjar)\
**Post date:** [June 18, 2024, 12:53am UTC](https://forum.arduino.cc/t/help-for-wifiserver/1272860/1 "2024-06-18T00:53:35Z")

</div>

I am having strange situation with my new Arduino Giga.  
I took program from tutorial , copy, paste and more or less it is working as expected.  
The WebServer as AP is not working but connecting to other network is working fine.  
So i was thinking it will be simple and proceeded with integrating into my project (made on Due with ethernet shield)  
So here is strange situation.  
If i will declare WifiServer and WifiClient in the main file, it is working fine.  
However if i will use additional file and define that file .h into main project file the compiler is happy and loads the program into device.  
But looks like it is having some dummy references now because it is garbage.

1. WifiServer defined in 2nd file will never work (my browser is not able to connect)  
If i will declare WifiServer in the main file and pass pointer to it to class or function in the other file it is working (almost).
2. So once i have this situation that WifiServer defined in main file. I have class that is using pointer to it to detect connection and so on.

And it is working to detect connections but not able to get incoming message:  
`
WiFiClient httpclient = (*serverHTTP).available();
// this is working ,
// also serverHTTP->available(); will work`

`
if (httpclient) {
//it is not 0 pointer and get in
if(debug)Serial.println("new client");
//i can see print in serial
int incommingMsgLen = 0;
if (httpclient.connected()) {
//it is getting into this condition, so it is working for connected
incommingMsgLen = httpclient.available();
// this returns 0
httpRequest.reserve(incommingMsgLen);
if (debug) {
Serial.print(F("Incomming Msg Length: "));
Serial.println(incommingMsgLen);
// this will print out 0
` Again if i will put the same code in main file, it will work 

I am adding #include \<Wifi.h\> in both files and i and suspecting that this is an issue

---

<div class="post-metadata">

**Author:** ![Juraj](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/juraj/32/238785_2.png) [@Juraj](https://forum.arduino.cc/u/Juraj)\
**Post date:** [June 18, 2024, 5:20am UTC](https://forum.arduino.cc/t/help-for-wifiserver/1272860/2 "2024-06-18T05:20:13Z")

</div>

are you on latest Mbed Core?  
has the second server a different port?

---

<div class="post-metadata">

**Author:** ![kenb4](https://avatars.discourse-cdn.com/v4/letter/k/bb73d2/32.png) [@kenb4](https://forum.arduino.cc/u/kenb4)\
**Post date:** [June 18, 2024, 7:48am UTC](https://forum.arduino.cc/t/help-for-wifiserver/1272860/3 "2024-06-18T07:48:14Z")

</div>

> [@](#):
>
> ```arduino
> int incommingMsgLen = 0;
> if (httpclient.connected()) {
> //it is getting into this condition, so it is working for connected
> incommingMsgLen = httpclient.available();
> 
> ```

Bytes "on the wire" can stall and come in groups/parts, so generally this should be more like

```cpp
int incommingMsgLen = 0;
while (httpclient.connected()) {
  if (incommingMsgLen = httpclient.available()) {

```

Of course, a genuine HTTP server would handle these "plumbing" details for you and present the captured request method, URL, headers, and body. But since you are trying to unravel your mystery, you can start there.

> [@](#):
>
> I am adding #include \<Wifi.h\> in both files and i and suspecting that this is an issue

A properly constructed header file can be included several times in the same file, and in nested files. The usual problem is when you forget to include it; each "compilation unit" needs its own.

---

<div class="post-metadata">

**Author:** ![lukjar](https://avatars.discourse-cdn.com/v4/letter/l/59ef9b/32.png) [@lukjar](https://forum.arduino.cc/u/lukjar)\
**Post date:** [June 18, 2024, 10:38pm UTC](https://forum.arduino.cc/t/help-for-wifiserver/1272860/4 "2024-06-18T22:38:25Z")

</div>

there is only 1 server ,  
How to check Mbed core version ?  
I am running latest arduino ide

---

<div class="post-metadata">

**Author:** ![Juraj](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/juraj/32/238785_2.png) [@Juraj](https://forum.arduino.cc/u/Juraj)\
**Post date:** [June 19, 2024, 5:23am UTC](https://forum.arduino.cc/t/help-for-wifiserver/1272860/5 "2024-06-19T05:23:18Z")

</div>

> [@lukjar](#):
>
> How to check Mbed core version ?

in Boards Manager

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [December 16, 2024, 5:23am UTC](https://forum.arduino.cc/t/help-for-wifiserver/1272860/6 "2024-12-16T05:23:34Z")

</div>

Closed on December 16, 2024, 5:23am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
